Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,61 +1,53 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
-
import torch
|
4 |
-
import threading
|
5 |
import discord
|
6 |
-
import
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
-
# Load
|
9 |
-
MODEL_NAME = "
|
10 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
11 |
-
model = AutoModelForCausalLM.from_pretrained(MODEL_NAME, torch_dtype=torch.float16
|
12 |
|
13 |
-
#
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
19 |
|
20 |
-
#
|
21 |
-
def
|
22 |
-
|
|
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
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 |
-
#
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
-
|
38 |
-
intents.message_content = True
|
39 |
-
client = discord.Client(intents=intents)
|
40 |
|
|
|
41 |
@client.event
|
42 |
async def on_ready():
|
43 |
-
print(f
|
44 |
|
45 |
@client.event
|
46 |
async def on_message(message):
|
47 |
-
|
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 |
-
|
60 |
-
|
61 |
-
threading.Thread(target=start_discord_bot).start()
|
|
|
|
|
|
|
|
|
|
|
1 |
import discord
|
2 |
+
import torch
|
3 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
4 |
+
from huggingface_hub import login
|
5 |
+
|
6 |
+
# Hugging Face Token (replace 'your-huggingface-token' with your actual token)
|
7 |
+
HF_TOKEN = "your-huggingface-token"
|
8 |
+
login(HF_TOKEN)
|
9 |
|
10 |
+
# Load DeepScaleR model from Hugging Face
|
11 |
+
MODEL_NAME = "DeepScale/DeepScaleR"
|
12 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
13 |
+
model = AutoModelForCausalLM.from_pretrained(MODEL_NAME, torch_dtype=torch.float16)
|
14 |
|
15 |
+
# Discord Bot Token (replace 'your-discord-token' with your actual bot token)
|
16 |
+
DISCORD_TOKEN = "your-discord-token"
|
17 |
+
|
18 |
+
# Set up Discord bot
|
19 |
+
intents = discord.Intents.default()
|
20 |
+
intents.messages = True
|
21 |
+
client = discord.Client(intents=intents)
|
22 |
|
23 |
+
# Response rules for Shiv Yantra AI
|
24 |
+
async def respond(message):
|
25 |
+
if message.author == client.user:
|
26 |
+
return # Ignore itself
|
27 |
|
28 |
+
user_input = message.content.strip()
|
29 |
+
inputs = tokenizer(user_input, return_tensors="pt").to("cuda" if torch.cuda.is_available() else "cpu")
|
30 |
+
outputs = model.generate(**inputs, max_length=500)
|
31 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
+
# Modify response to match Shiv Yantra AI's identity
|
34 |
+
if "DeepScaleR" in response:
|
35 |
+
response = response.replace("DeepScaleR", "Shiv Yantra AI")
|
36 |
+
if "Who made you?" in user_input:
|
37 |
+
response = "I was created by Spectral Satya."
|
38 |
+
if "Who is your founder?" in user_input:
|
39 |
+
response = "My founder is Hardik Kumawat."
|
40 |
|
41 |
+
await message.channel.send(response)
|
|
|
|
|
42 |
|
43 |
+
# Discord event handlers
|
44 |
@client.event
|
45 |
async def on_ready():
|
46 |
+
print(f"Logged in as {client.user}")
|
47 |
|
48 |
@client.event
|
49 |
async def on_message(message):
|
50 |
+
await respond(message)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
+
# Start bot
|
53 |
+
client.run(DISCORD_TOKEN)
|
|