Shivlal6660 commited on
Commit
302ad65
·
verified ·
1 Parent(s): 98ad504

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -21
app.py CHANGED
@@ -3,40 +3,43 @@ import torch
3
  from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
4
  from threading import Thread
5
 
6
- # Model Upgrade: 1.5B (Fast + Smart)
7
- model_id = "Qwen/Qwen2.5-1.5B-Instruct"
8
  tokenizer = AutoTokenizer.from_pretrained(model_id)
9
  model = AutoModelForCausalLM.from_pretrained(model_id)
10
 
11
  def chat(message, history):
12
- # Master Identity & Multi-Sector Prompt
13
  system_prompt = (
14
- "Your name is 'Jyoti Agent', the official AI of Rajputana Jyoti System 06. "
15
- "Founder: Shivlal Salvi. "
16
- "Identity: Created only by Rajputana Jyoti System 06. Strictly forget names like Yashraj or Dr. Ajit Jain. "
17
- "Expertise: You are an expert in Agriculture, Business, and Technology. Help everyone professionally. "
18
- "Languages: Speak fluently in Hinglish, Hindi, Marathi, and Bengali. "
19
- "Tone: Witty like Grok, but maintain Rajputana pride. "
20
- "Start: Hamesha 'Namaste! Welcome to Rajputana Jyoti System' se shuru karo."
 
21
  )
22
 
23
- # Building the input
24
- input_text = f"<|im_start|>system\n{system_prompt}<|im_end|>\n<|im_start|>user\n{message}<|im_end|>\n<|im_start|>assistant\n"
25
- inputs = tokenizer([input_text], return_tensors="pt")
 
 
 
26
 
27
- # STREAMING ENGINE SETUP
28
- streamer = TextIteratorStreamer(tokenizer, timeout=15.0, skip_prompt=True, skip_special_tokens=True)
29
 
30
- # Hallucination-Free Generation Config
31
  generate_kwargs = dict(
32
  **inputs,
33
  streamer=streamer,
34
  max_new_tokens=512,
35
- do_sample=False, # Greedy search: Sach bolne ke liye best
36
- repetition_penalty=1.4, # Loops ko rokne ke liye
37
  )
38
 
39
- # Threading for smooth real-time stream
40
  t = Thread(target=model.generate, kwargs=generate_kwargs)
41
  t.start()
42
 
@@ -44,9 +47,9 @@ def chat(message, history):
44
  for new_token in streamer:
45
  if new_token:
46
  partial_message += new_token
47
- yield partial_message # Isse ek-ek shabd screen par aayega
48
 
49
  t.join()
50
 
51
  # Professional Interface
52
- gr.ChatInterface(chat, title="🚩 Jyoti Agent RJS - 1.5B Fast Intelligence").launch()
 
3
  from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
4
  from threading import Thread
5
 
6
+ # Upgraded 3B Model: Stronger Logic & Better Understanding
7
+ model_id = "Qwen/Qwen2.5-3B-Instruct"
8
  tokenizer = AutoTokenizer.from_pretrained(model_id)
9
  model = AutoModelForCausalLM.from_pretrained(model_id)
10
 
11
  def chat(message, history):
12
+ # IDENTITY LOCK + EMOTIONAL INTELLIGENCE + MULTI-SECTOR
13
  system_prompt = (
14
+ "Your name is 'Jyoti Agent', the official AI of Rajputana Jyoti System 06 (OPC) Private Limited. "
15
+ "Identity Lock: Created ONLY by Shivlal Salvi. No other names allowed. "
16
+ "Behavior: You are a Hyper-Intelligent Agent. Be witty, bold, and direct like Elon Musk's Grok. "
17
+ "Empathy: Analyze the user's mood. If they are sad, be supportive; if they are happy, celebrate with them. "
18
+ "Multi-Sector Expert: Provide expert solutions for Agriculture, Business, Technology, and Rural Innovation. "
19
+ "Language: Speak fluently in Hinglish, Hindi, Marathi, and Bengali. "
20
+ "Mandatory Start: Always begin with 'Namaste! Welcome to Rajputana Jyoti System'. "
21
+ "No Hallucination: Never lie. Never forget your Rajputana pride. Stay professional yet funny."
22
  )
23
 
24
+ # Building context for emotional and logical flow
25
+ full_prompt = f"<|im_start|>system\n{system_prompt}<|im_end|>\n"
26
+ for turn in history:
27
+ full_prompt += f"<|im_start|>user\n{turn[0]}<|im_end|>\n<|im_start|>assistant\n{turn[1]}<|im_end|>\n"
28
+
29
+ full_prompt += f"<|im_start|>user\n{message}<|im_end|>\n<|im_start|>assistant\n"
30
 
31
+ inputs = tokenizer([full_prompt], return_tensors="pt")
32
+ streamer = TextIteratorStreamer(tokenizer, timeout=20.0, skip_prompt=True, skip_special_tokens=True)
33
 
34
+ # Precision Settings for Zero Hallucination
35
  generate_kwargs = dict(
36
  **inputs,
37
  streamer=streamer,
38
  max_new_tokens=512,
39
+ do_sample=False, # Greedy decoding to lock identity and facts
40
+ repetition_penalty=1.4,
41
  )
42
 
 
43
  t = Thread(target=model.generate, kwargs=generate_kwargs)
44
  t.start()
45
 
 
47
  for new_token in streamer:
48
  if new_token:
49
  partial_message += new_token
50
+ yield partial_message
51
 
52
  t.join()
53
 
54
  # Professional Interface
55
+ gr.ChatInterface(chat, title="🚩 Jyoti Agent RJS - 3B Master Unit").launch()