Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,65 +1,18 @@
|
|
1 |
-
import
|
2 |
-
import os
|
3 |
-
import torch
|
4 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
5 |
-
|
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
|
32 |
-
async def on_ready():
|
33 |
-
print(f'Logged in as {client.user}')
|
34 |
-
|
35 |
-
@client.event
|
36 |
-
async def on_message(message):
|
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 |
-
#
|
57 |
-
|
58 |
-
|
|
|
59 |
|
60 |
-
|
61 |
-
|
62 |
-
|
|
|
|
|
63 |
|
64 |
-
|
65 |
-
|
|
|
|
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 |
+
# Function to generate AI responses
|
11 |
+
def generate_response(prompt):
|
12 |
+
inputs = tokenizer(prompt, return_tensors="pt", truncation=True, max_length=2048)
|
13 |
+
output = model.generate(**inputs, max_new_tokens=200)
|
14 |
+
return tokenizer.decode(output[0], skip_special_tokens=True)
|
15 |
|
16 |
+
# Launch API for Discord bot
|
17 |
+
iface = gr.Interface(fn=generate_response, inputs="text", outputs="text")
|
18 |
+
iface.launch(server_name="0.0.0.0", server_port=7860, share=False)
|