Hardik5456 commited on
Commit
81721b3
·
verified ·
1 Parent(s): 9d909c7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -46
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 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()
 
 
 
 
 
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)