Spaces:
Runtime error
Runtime error
some cleanup
Browse files
app.py
CHANGED
|
@@ -16,30 +16,18 @@ from gradio_client import Client
|
|
| 16 |
import gradio_client as grc
|
| 17 |
from gradio_client.utils import QueueError
|
| 18 |
|
|
|
|
| 19 |
event = Event()
|
| 20 |
DISCORD_TOKEN = os.getenv("DISCORD_TOKEN")
|
| 21 |
-
|
| 22 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 23 |
codellama_client = Client("https://huggingface-projects-codellama-13b-chat.hf.space/", HF_TOKEN)
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
codellama_threadid_userid_dictionary = {}
|
| 30 |
codellama_threadid_conversation = {}
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
intents = discord.Intents.default()
|
| 40 |
intents.message_content = True
|
| 41 |
bot = commands.Bot(command_prefix="/", intents=intents)
|
| 42 |
|
|
|
|
| 43 |
@bot.event
|
| 44 |
async def on_ready():
|
| 45 |
print(f"Logged in as {bot.user} (ID: {bot.user.id})")
|
|
@@ -49,7 +37,6 @@ async def on_ready():
|
|
| 49 |
print("------")
|
| 50 |
|
| 51 |
|
| 52 |
-
|
| 53 |
@bot.hybrid_command(
|
| 54 |
name="codellama",
|
| 55 |
description="Enter a prompt to generate code!",
|
|
@@ -62,7 +49,6 @@ async def codellama(ctx, prompt: str):
|
|
| 62 |
print(f"Error: (app.py){e}")
|
| 63 |
|
| 64 |
|
| 65 |
-
|
| 66 |
@bot.event
|
| 67 |
async def on_message(message):
|
| 68 |
"""Checks channel and continues codellama conversation if it's the right Discord Thread"""
|
|
@@ -73,12 +59,6 @@ async def on_message(message):
|
|
| 73 |
print(f"Error: {e}")
|
| 74 |
|
| 75 |
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
async def try_codellama(ctx, prompt):
|
| 83 |
"""Generates text based on a given prompt"""
|
| 84 |
try:
|
|
@@ -88,8 +68,6 @@ async def try_codellama(ctx, prompt):
|
|
| 88 |
message = await ctx.send(f"**{prompt}** - {ctx.author.mention}")
|
| 89 |
thread = await message.create_thread(name=prompt[:100])
|
| 90 |
|
| 91 |
-
|
| 92 |
-
|
| 93 |
loop = asyncio.get_running_loop()
|
| 94 |
output_code = await loop.run_in_executor(None, codellama_initial_generation, prompt, thread)
|
| 95 |
codellama_threadid_userid_dictionary[thread.id] = ctx.author.id
|
|
@@ -100,9 +78,6 @@ async def try_codellama(ctx, prompt):
|
|
| 100 |
print(f"try_codellama Error: {e}")
|
| 101 |
|
| 102 |
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
def codellama_initial_generation(prompt, thread):
|
| 107 |
"""job.submit inside of run_in_executor = more consistent bot behavior"""
|
| 108 |
global codellama_threadid_conversation
|
|
@@ -131,27 +106,6 @@ def codellama_initial_generation(prompt, thread):
|
|
| 131 |
return response
|
| 132 |
|
| 133 |
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
async def continue_codellama(message):
|
| 156 |
"""Continues a given conversation based on chat_history"""
|
| 157 |
try:
|
|
@@ -213,13 +167,12 @@ def run_bot():
|
|
| 213 |
|
| 214 |
|
| 215 |
threading.Thread(target=run_bot).start()
|
| 216 |
-
|
| 217 |
event.wait()
|
| 218 |
|
| 219 |
with gr.Blocks() as demo:
|
| 220 |
gr.Markdown(
|
| 221 |
"""
|
| 222 |
-
# Discord bot of https://huggingface.co/spaces/
|
| 223 |
https://discord.com/api/oauth2/authorize?client_id=1152238037355474964&permissions=326417516544&scope=bot
|
| 224 |
"""
|
| 225 |
)
|
|
|
|
| 16 |
import gradio_client as grc
|
| 17 |
from gradio_client.utils import QueueError
|
| 18 |
|
| 19 |
+
|
| 20 |
event = Event()
|
| 21 |
DISCORD_TOKEN = os.getenv("DISCORD_TOKEN")
|
|
|
|
| 22 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 23 |
codellama_client = Client("https://huggingface-projects-codellama-13b-chat.hf.space/", HF_TOKEN)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
codellama_threadid_userid_dictionary = {}
|
| 25 |
codellama_threadid_conversation = {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
intents = discord.Intents.default()
|
| 27 |
intents.message_content = True
|
| 28 |
bot = commands.Bot(command_prefix="/", intents=intents)
|
| 29 |
|
| 30 |
+
|
| 31 |
@bot.event
|
| 32 |
async def on_ready():
|
| 33 |
print(f"Logged in as {bot.user} (ID: {bot.user.id})")
|
|
|
|
| 37 |
print("------")
|
| 38 |
|
| 39 |
|
|
|
|
| 40 |
@bot.hybrid_command(
|
| 41 |
name="codellama",
|
| 42 |
description="Enter a prompt to generate code!",
|
|
|
|
| 49 |
print(f"Error: (app.py){e}")
|
| 50 |
|
| 51 |
|
|
|
|
| 52 |
@bot.event
|
| 53 |
async def on_message(message):
|
| 54 |
"""Checks channel and continues codellama conversation if it's the right Discord Thread"""
|
|
|
|
| 59 |
print(f"Error: {e}")
|
| 60 |
|
| 61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
async def try_codellama(ctx, prompt):
|
| 63 |
"""Generates text based on a given prompt"""
|
| 64 |
try:
|
|
|
|
| 68 |
message = await ctx.send(f"**{prompt}** - {ctx.author.mention}")
|
| 69 |
thread = await message.create_thread(name=prompt[:100])
|
| 70 |
|
|
|
|
|
|
|
| 71 |
loop = asyncio.get_running_loop()
|
| 72 |
output_code = await loop.run_in_executor(None, codellama_initial_generation, prompt, thread)
|
| 73 |
codellama_threadid_userid_dictionary[thread.id] = ctx.author.id
|
|
|
|
| 78 |
print(f"try_codellama Error: {e}")
|
| 79 |
|
| 80 |
|
|
|
|
|
|
|
|
|
|
| 81 |
def codellama_initial_generation(prompt, thread):
|
| 82 |
"""job.submit inside of run_in_executor = more consistent bot behavior"""
|
| 83 |
global codellama_threadid_conversation
|
|
|
|
| 106 |
return response
|
| 107 |
|
| 108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
async def continue_codellama(message):
|
| 110 |
"""Continues a given conversation based on chat_history"""
|
| 111 |
try:
|
|
|
|
| 167 |
|
| 168 |
|
| 169 |
threading.Thread(target=run_bot).start()
|
|
|
|
| 170 |
event.wait()
|
| 171 |
|
| 172 |
with gr.Blocks() as demo:
|
| 173 |
gr.Markdown(
|
| 174 |
"""
|
| 175 |
+
# Discord bot of https://huggingface.co/spaces/huggingface-projects/codellama-13b-chat
|
| 176 |
https://discord.com/api/oauth2/authorize?client_id=1152238037355474964&permissions=326417516544&scope=bot
|
| 177 |
"""
|
| 178 |
)
|