Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -2,18 +2,30 @@ import discord
|
|
2 |
import os
|
3 |
import torch
|
4 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
|
5 |
|
6 |
-
# Load
|
7 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
8 |
DISCORD_TOKEN = os.getenv("DISCORD_TOKEN")
|
9 |
|
10 |
-
#
|
11 |
-
|
12 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name, use_auth_token=HF_TOKEN)
|
13 |
-
model = AutoModelForCausalLM.from_pretrained(model_name, use_auth_token=HF_TOKEN)
|
14 |
|
15 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
intents = discord.Intents.default()
|
|
|
17 |
client = discord.Client(intents=intents)
|
18 |
|
19 |
@client.event
|
@@ -25,12 +37,29 @@ async def on_message(message):
|
|
25 |
if message.author == client.user:
|
26 |
return
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
-
|
|
|
|
|
34 |
|
35 |
-
# Run
|
36 |
-
|
|
|
2 |
import os
|
3 |
import torch
|
4 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
5 |
+
from flask import Flask
|
6 |
|
7 |
+
# Load environment variables (Hugging Face & Discord tokens)
|
8 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
9 |
DISCORD_TOKEN = os.getenv("DISCORD_TOKEN")
|
10 |
|
11 |
+
# Define model name (Make sure this matches your uploaded model in Hugging Face)
|
12 |
+
MODEL_NAME = "Hardik5456/DeepScaleR"
|
|
|
|
|
13 |
|
14 |
+
# Load Model & Tokenizer
|
15 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
16 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME, token=HF_TOKEN)
|
17 |
+
model = AutoModelForCausalLM.from_pretrained(MODEL_NAME, token=HF_TOKEN).to(device)
|
18 |
+
|
19 |
+
# Initialize Flask for Hugging Face Space (Prevents Space from Sleeping)
|
20 |
+
app = Flask(__name__)
|
21 |
+
|
22 |
+
@app.route("/")
|
23 |
+
def home():
|
24 |
+
return "Shiv Yantra AI is running!"
|
25 |
+
|
26 |
+
# Discord Bot Setup
|
27 |
intents = discord.Intents.default()
|
28 |
+
intents.messages = True
|
29 |
client = discord.Client(intents=intents)
|
30 |
|
31 |
@client.event
|
|
|
37 |
if message.author == client.user:
|
38 |
return
|
39 |
|
40 |
+
# Shiv Yantra AI's Special Responses
|
41 |
+
if message.content.lower() == "who are you?":
|
42 |
+
await message.channel.send("I am Shiv Yantra AI, an advanced intelligence created for cinematic AI filmmaking.")
|
43 |
+
elif message.content.lower() == "who made you?":
|
44 |
+
await message.channel.send("I was created by Spectral Satya.")
|
45 |
+
elif message.content.lower() == "who is the founder?":
|
46 |
+
await message.channel.send("Hardik Kumawat is the visionary behind this AI.")
|
47 |
+
else:
|
48 |
+
# Generate AI Response
|
49 |
+
input_text = message.content
|
50 |
+
input_ids = tokenizer.encode(input_text, return_tensors="pt").to(device)
|
51 |
+
output = model.generate(input_ids, max_length=200)
|
52 |
+
response = tokenizer.decode(output[0], skip_special_tokens=True)
|
53 |
+
|
54 |
+
await message.channel.send(response)
|
55 |
+
|
56 |
+
# Run Flask & Discord Bot
|
57 |
+
if __name__ == "__main__":
|
58 |
+
import threading
|
59 |
|
60 |
+
# Start Discord Bot in a separate thread
|
61 |
+
discord_thread = threading.Thread(target=lambda: client.run(DISCORD_TOKEN))
|
62 |
+
discord_thread.start()
|
63 |
|
64 |
+
# Run Flask App for Hugging Face Space
|
65 |
+
app.run(host="0.0.0.0", port=7860)
|