Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,53 +1,49 @@
|
|
|
|
1 |
import discord
|
2 |
import torch
|
3 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
4 |
from huggingface_hub import login
|
|
|
5 |
|
6 |
-
#
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
login(HF_TOKEN)
|
9 |
|
10 |
-
# Load DeepScaleR model
|
11 |
-
MODEL_NAME = "
|
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 |
-
#
|
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
|
47 |
|
48 |
@client.event
|
49 |
async def on_message(message):
|
50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
-
#
|
53 |
client.run(DISCORD_TOKEN)
|
|
|
1 |
+
import os
|
2 |
import discord
|
3 |
import torch
|
4 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
5 |
from huggingface_hub import login
|
6 |
+
from dotenv import load_dotenv
|
7 |
|
8 |
+
# Load environment variables
|
9 |
+
load_dotenv()
|
10 |
+
HF_TOKEN = os.getenv("HF_TOKEN")
|
11 |
+
DISCORD_TOKEN = os.getenv("DISCORD_TOKEN")
|
12 |
+
|
13 |
+
if not HF_TOKEN:
|
14 |
+
raise ValueError("Hugging Face token is missing. Set HF_TOKEN in the environment variables.")
|
15 |
+
|
16 |
+
if not DISCORD_TOKEN:
|
17 |
+
raise ValueError("Discord bot token is missing. Set DISCORD_TOKEN in the environment variables.")
|
18 |
+
|
19 |
+
# Authenticate with Hugging Face
|
20 |
login(HF_TOKEN)
|
21 |
|
22 |
+
# Load DeepScaleR model and tokenizer
|
23 |
+
MODEL_NAME = "Your_HuggingFace_Repo/DeepScaleR" # Replace with your model repo name
|
24 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
25 |
+
model = AutoModelForCausalLM.from_pretrained(MODEL_NAME, torch_dtype=torch.float16).to("cuda" if torch.cuda.is_available() else "cpu")
|
|
|
|
|
|
|
26 |
|
27 |
+
# Initialize Discord bot
|
28 |
intents = discord.Intents.default()
|
29 |
intents.messages = True
|
30 |
client = discord.Client(intents=intents)
|
31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
@client.event
|
33 |
async def on_ready():
|
34 |
+
print(f'Logged in as {client.user}')
|
35 |
|
36 |
@client.event
|
37 |
async def on_message(message):
|
38 |
+
if message.author == client.user:
|
39 |
+
return
|
40 |
+
|
41 |
+
input_text = message.content
|
42 |
+
inputs = tokenizer(input_text, return_tensors="pt").to(model.device)
|
43 |
+
output = model.generate(**inputs, max_length=200)
|
44 |
+
response = tokenizer.decode(output[0], skip_special_tokens=True)
|
45 |
+
|
46 |
+
await message.channel.send(response)
|
47 |
|
48 |
+
# Run Discord bot
|
49 |
client.run(DISCORD_TOKEN)
|