Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,18 +1,61 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
import torch
|
|
|
|
|
|
|
4 |
|
5 |
-
# Load DeepScaleR model
|
6 |
MODEL_NAME = "agentica-org/DeepScaleR-1.5B-Preview"
|
7 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
8 |
-
model = AutoModelForCausalLM.from_pretrained(MODEL_NAME)
|
9 |
|
10 |
-
#
|
11 |
def generate_response(prompt):
|
12 |
-
inputs = tokenizer(prompt, return_tensors="pt"
|
13 |
-
|
14 |
-
|
|
|
15 |
|
16 |
-
#
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
import torch
|
4 |
+
import threading
|
5 |
+
import discord
|
6 |
+
import asyncio
|
7 |
|
8 |
+
# Load the DeepScaleR model and tokenizer
|
9 |
MODEL_NAME = "agentica-org/DeepScaleR-1.5B-Preview"
|
10 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
11 |
+
model = AutoModelForCausalLM.from_pretrained(MODEL_NAME, torch_dtype=torch.float16, device_map="auto")
|
12 |
|
13 |
+
# Define the function to generate responses
|
14 |
def generate_response(prompt):
|
15 |
+
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
|
16 |
+
outputs = model.generate(inputs.input_ids, max_length=100, do_sample=True, top_p=0.95, top_k=60)
|
17 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
18 |
+
return response
|
19 |
|
20 |
+
# Set up Gradio interface
|
21 |
+
def gradio_interface(input_text):
|
22 |
+
return generate_response(input_text)
|
23 |
+
|
24 |
+
with gr.Blocks() as demo:
|
25 |
+
gr.Markdown("## DeepScaleR Chatbot")
|
26 |
+
chatbot = gr.Chatbot()
|
27 |
+
with gr.Row():
|
28 |
+
with gr.Column():
|
29 |
+
user_input = gr.Textbox(show_label=False, placeholder="Enter your message")
|
30 |
+
with gr.Column():
|
31 |
+
submit_btn = gr.Button("Send")
|
32 |
+
submit_btn.click(gradio_interface, inputs=user_input, outputs=chatbot)
|
33 |
+
|
34 |
+
# Discord bot setup
|
35 |
+
DISCORD_TOKEN = "YOUR_DISCORD_BOT_TOKEN"
|
36 |
+
|
37 |
+
intents = discord.Intents.default()
|
38 |
+
intents.message_content = True
|
39 |
+
client = discord.Client(intents=intents)
|
40 |
+
|
41 |
+
@client.event
|
42 |
+
async def on_ready():
|
43 |
+
print(f'Logged in as {client.user}')
|
44 |
+
|
45 |
+
@client.event
|
46 |
+
async def on_message(message):
|
47 |
+
if message.author == client.user:
|
48 |
+
return
|
49 |
+
response = generate_response(message.content)
|
50 |
+
await message.channel.send(response)
|
51 |
+
|
52 |
+
# Run the Gradio app and Discord bot concurrently
|
53 |
+
def start_gradio():
|
54 |
+
demo.launch()
|
55 |
+
|
56 |
+
def start_discord_bot():
|
57 |
+
asyncio.run(client.start(DISCORD_TOKEN))
|
58 |
+
|
59 |
+
if __name__ == "__main__":
|
60 |
+
threading.Thread(target=start_gradio).start()
|
61 |
+
threading.Thread(target=start_discord_bot).start()
|