Spaces:
Runtime error
Runtime error
Commit
·
c914190
1
Parent(s):
1c79aae
Upload folder using huggingface_hub
Browse files- .gitignore +162 -0
- .vscode/settings.json +6 -0
- README.md +3 -7
- app.py +8 -0
- main.py +37 -0
- requirements.txt +4 -0
- src/__pycache__/chatbot.cpython-310.pyc +0 -0
- src/__pycache__/imagebot.cpython-310.pyc +0 -0
- src/chatbot.py +21 -0
- src/imagebot.py +12 -0
- src/trainingbot.py +27 -0
- test.py +23 -0
.gitignore
ADDED
@@ -0,0 +1,162 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
test.py
|
2 |
+
.vscode
|
3 |
+
# Byte-compiled / optimized / DLL files
|
4 |
+
__pycache__/
|
5 |
+
*.py[cod]
|
6 |
+
*$py.class
|
7 |
+
|
8 |
+
# C extensions
|
9 |
+
*.so
|
10 |
+
|
11 |
+
# Distribution / packaging
|
12 |
+
.Python
|
13 |
+
build/
|
14 |
+
develop-eggs/
|
15 |
+
dist/
|
16 |
+
downloads/
|
17 |
+
eggs/
|
18 |
+
.eggs/
|
19 |
+
lib/
|
20 |
+
lib64/
|
21 |
+
parts/
|
22 |
+
sdist/
|
23 |
+
var/
|
24 |
+
wheels/
|
25 |
+
share/python-wheels/
|
26 |
+
*.egg-info/
|
27 |
+
.installed.cfg
|
28 |
+
*.egg
|
29 |
+
MANIFEST
|
30 |
+
|
31 |
+
# PyInstaller
|
32 |
+
# Usually these files are written by a python script from a template
|
33 |
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
34 |
+
*.manifest
|
35 |
+
*.spec
|
36 |
+
|
37 |
+
# Installer logs
|
38 |
+
pip-log.txt
|
39 |
+
pip-delete-this-directory.txt
|
40 |
+
|
41 |
+
# Unit test / coverage reports
|
42 |
+
htmlcov/
|
43 |
+
.tox/
|
44 |
+
.nox/
|
45 |
+
.coverage
|
46 |
+
.coverage.*
|
47 |
+
.cache
|
48 |
+
nosetests.xml
|
49 |
+
coverage.xml
|
50 |
+
*.cover
|
51 |
+
*.py,cover
|
52 |
+
.hypothesis/
|
53 |
+
.pytest_cache/
|
54 |
+
cover/
|
55 |
+
|
56 |
+
# Translations
|
57 |
+
*.mo
|
58 |
+
*.pot
|
59 |
+
|
60 |
+
# Django stuff:
|
61 |
+
*.log
|
62 |
+
local_settings.py
|
63 |
+
db.sqlite3
|
64 |
+
db.sqlite3-journal
|
65 |
+
|
66 |
+
# Flask stuff:
|
67 |
+
instance/
|
68 |
+
.webassets-cache
|
69 |
+
|
70 |
+
# Scrapy stuff:
|
71 |
+
.scrapy
|
72 |
+
|
73 |
+
# Sphinx documentation
|
74 |
+
docs/_build/
|
75 |
+
|
76 |
+
# PyBuilder
|
77 |
+
.pybuilder/
|
78 |
+
target/
|
79 |
+
|
80 |
+
# Jupyter Notebook
|
81 |
+
.ipynb_checkpoints
|
82 |
+
|
83 |
+
# IPython
|
84 |
+
profile_default/
|
85 |
+
ipython_config.py
|
86 |
+
|
87 |
+
# pyenv
|
88 |
+
# For a library or package, you might want to ignore these files since the code is
|
89 |
+
# intended to run in multiple environments; otherwise, check them in:
|
90 |
+
# .python-version
|
91 |
+
|
92 |
+
# pipenv
|
93 |
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
94 |
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
95 |
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
96 |
+
# install all needed dependencies.
|
97 |
+
#Pipfile.lock
|
98 |
+
|
99 |
+
# poetry
|
100 |
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
101 |
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
102 |
+
# commonly ignored for libraries.
|
103 |
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
104 |
+
#poetry.lock
|
105 |
+
|
106 |
+
# pdm
|
107 |
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
108 |
+
#pdm.lock
|
109 |
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
110 |
+
# in version control.
|
111 |
+
# https://pdm.fming.dev/#use-with-ide
|
112 |
+
.pdm.toml
|
113 |
+
|
114 |
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
115 |
+
__pypackages__/
|
116 |
+
|
117 |
+
# Celery stuff
|
118 |
+
celerybeat-schedule
|
119 |
+
celerybeat.pid
|
120 |
+
|
121 |
+
# SageMath parsed files
|
122 |
+
*.sage.py
|
123 |
+
|
124 |
+
# Environments
|
125 |
+
.env
|
126 |
+
.venv
|
127 |
+
env/
|
128 |
+
venv/
|
129 |
+
ENV/
|
130 |
+
env.bak/
|
131 |
+
venv.bak/
|
132 |
+
|
133 |
+
# Spyder project settings
|
134 |
+
.spyderproject
|
135 |
+
.spyproject
|
136 |
+
|
137 |
+
# Rope project settings
|
138 |
+
.ropeproject
|
139 |
+
|
140 |
+
# mkdocs documentation
|
141 |
+
/site
|
142 |
+
|
143 |
+
# mypy
|
144 |
+
.mypy_cache/
|
145 |
+
.dmypy.json
|
146 |
+
dmypy.json
|
147 |
+
|
148 |
+
# Pyre type checker
|
149 |
+
.pyre/
|
150 |
+
|
151 |
+
# pytype static type analyzer
|
152 |
+
.pytype/
|
153 |
+
|
154 |
+
# Cython debug symbols
|
155 |
+
cython_debug/
|
156 |
+
|
157 |
+
# PyCharm
|
158 |
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
159 |
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
160 |
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
161 |
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
162 |
+
#.idea/
|
.vscode/settings.json
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"[python]": {
|
3 |
+
"editor.defaultFormatter": "ms-python.black-formatter"
|
4 |
+
},
|
5 |
+
"python.formatting.provider": "none"
|
6 |
+
}
|
README.md
CHANGED
@@ -1,12 +1,8 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
|
4 |
-
colorFrom: red
|
5 |
-
colorTo: gray
|
6 |
sdk: gradio
|
7 |
sdk_version: 3.40.1
|
8 |
-
app_file: app.py
|
9 |
-
pinned: false
|
10 |
---
|
11 |
|
12 |
-
|
|
|
1 |
---
|
2 |
+
title: chatbot
|
3 |
+
app_file: .\app.py
|
|
|
|
|
4 |
sdk: gradio
|
5 |
sdk_version: 3.40.1
|
|
|
|
|
6 |
---
|
7 |
|
8 |
+
# discord_bot
|
app.py
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
|
4 |
+
def slow_echo(message, history):
|
5 |
+
return message
|
6 |
+
|
7 |
+
|
8 |
+
demo = gr.ChatInterface(slow_echo).queue().launch()
|
main.py
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import discord
|
3 |
+
from discord.ext import commands
|
4 |
+
from src.chatbot import Chatbot
|
5 |
+
from src.imagebot import Imagebot
|
6 |
+
|
7 |
+
|
8 |
+
intents = discord.Intents.default()
|
9 |
+
bot = commands.Bot(command_prefix="/", intents=intents)
|
10 |
+
chatbot = Chatbot(os.environ["poe_api_token"])
|
11 |
+
imagebot = Imagebot(os.environ["replicate_api_token"])
|
12 |
+
|
13 |
+
|
14 |
+
@bot.event
|
15 |
+
async def on_ready():
|
16 |
+
print(f"Logged in as {bot.user} (ID: {bot.user.id})")
|
17 |
+
|
18 |
+
|
19 |
+
@bot.command(name="q")
|
20 |
+
async def q(ctx, *query):
|
21 |
+
query = " ".join(query)
|
22 |
+
await ctx.send(f"{chatbot.query_from_api(query=query)}")
|
23 |
+
|
24 |
+
|
25 |
+
@bot.command(name="gen")
|
26 |
+
async def gen(ctx, *query):
|
27 |
+
query = " ".join(query)
|
28 |
+
await ctx.send(imagebot.generate_image(query=query))
|
29 |
+
|
30 |
+
|
31 |
+
@bot.command(name="python")
|
32 |
+
async def python(ctx, *query):
|
33 |
+
query = " ".join(query)
|
34 |
+
await ctx.send(f"{exec(query)}")
|
35 |
+
|
36 |
+
|
37 |
+
bot.run(os.environ["discord_token"])
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
urllib3==1.26.5
|
2 |
+
poe-api
|
3 |
+
discord.py
|
4 |
+
replicate
|
src/__pycache__/chatbot.cpython-310.pyc
ADDED
Binary file (924 Bytes). View file
|
|
src/__pycache__/imagebot.cpython-310.pyc
ADDED
Binary file (859 Bytes). View file
|
|
src/chatbot.py
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import poe
|
2 |
+
import logging
|
3 |
+
|
4 |
+
|
5 |
+
class Chatbot:
|
6 |
+
def __init__(self, token, bot_name: str = "chinchilla"):
|
7 |
+
self.bot_name = bot_name
|
8 |
+
try:
|
9 |
+
poe.logger.setLevel(logging.INFO)
|
10 |
+
self.client = poe.Client(token)
|
11 |
+
|
12 |
+
except Exception as e:
|
13 |
+
print(e)
|
14 |
+
|
15 |
+
def query_from_api(self, query):
|
16 |
+
response = ""
|
17 |
+
for chunk in self.client.send_message(self.bot_name, query, with_chat_break=True):
|
18 |
+
word = chunk["text_new"]
|
19 |
+
response += word
|
20 |
+
|
21 |
+
return response
|
src/imagebot.py
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import replicate
|
2 |
+
|
3 |
+
|
4 |
+
class Imagebot:
|
5 |
+
def __init__(self, token) -> None:
|
6 |
+
self.api = replicate.Client(api_token=token)
|
7 |
+
self.model = self.api.models.get("stability-ai/stable-diffusion")
|
8 |
+
self.version = self.model.versions.get("db21e45d3f7023abc2a46ee38a23973f6dce16bb082a930b0c49861f96d1e5bf")
|
9 |
+
|
10 |
+
def generate_image(self, query):
|
11 |
+
output_url = self.version.predict(prompt=query)[0]
|
12 |
+
return output_url
|
src/trainingbot.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import discord
|
2 |
+
import asyncio
|
3 |
+
|
4 |
+
|
5 |
+
class Trainingbot:
|
6 |
+
def __init__(self, token, channel_id) -> None:
|
7 |
+
self.token = token
|
8 |
+
self.channel_id = channel_id
|
9 |
+
self.loss_dict = {"train": [], "eval": []}
|
10 |
+
|
11 |
+
intents = discord.Intents.default()
|
12 |
+
self.client = discord.Client(intents=intents)
|
13 |
+
self.channel = self.client.get_channel(channel_id)
|
14 |
+
|
15 |
+
def append_loss(self, train_loss, eval_loss=None):
|
16 |
+
self.loss_dict.append(train_loss)
|
17 |
+
if eval_loss:
|
18 |
+
self.loss_dict.append(eval_loss)
|
19 |
+
|
20 |
+
async def log_loss(self):
|
21 |
+
if len(self.loss_dict["eval"]) > 0:
|
22 |
+
await self.channel.send(f"Train loss: {self.loss_dict['train'][-1]} \n Eval loss: {self.loss_dict['eval'][-1]}")
|
23 |
+
else:
|
24 |
+
await self.channel.send(f"Train loss: {self.loss_dict['train'][-1]}")
|
25 |
+
|
26 |
+
if __name__ == '__main__':
|
27 |
+
|
test.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import discord
|
2 |
+
import asyncio
|
3 |
+
|
4 |
+
# Set up the Discord client and log in with the bot token
|
5 |
+
client = discord.Client()
|
6 |
+
TOKEN = "your_bot_token_here"
|
7 |
+
channel_id = "your_channel_id_here"
|
8 |
+
|
9 |
+
|
10 |
+
# Function to send a message to a specific channel in your Discord server
|
11 |
+
async def send_message(message):
|
12 |
+
channel = client.get_channel(channel_id)
|
13 |
+
await channel.send(message)
|
14 |
+
|
15 |
+
|
16 |
+
# Your training loop
|
17 |
+
for epoch in range(num_epochs):
|
18 |
+
# Train your model and calculate the training loss
|
19 |
+
|
20 |
+
# After every a number of epochs, send the training loss to Discord
|
21 |
+
if epoch % num_epochs_to_log == 0:
|
22 |
+
message = f"Epoch {epoch}: training loss = {training_loss}"
|
23 |
+
asyncio.run(send_message(message))
|