Patel Traders commited on
Commit
0f16b8a
·
verified ·
1 Parent(s): 6b9b43d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -38
app.py CHANGED
@@ -1,6 +1,6 @@
1
- # --- हनुमान AI: जेम्मा मास्टर एडिशन (स्वतंत्र एवं अजेय) ---
2
- # मार्गदर्शक: दिव्य पटेल जी | स्थान: भारत 🇮🇳
3
- # नीकी विशेषता: यह संस्करण यूजे एक्सेस टो का योग कके गेटेड मॉडलोड कर है।
4
 
5
  import gradio as gr
6
  import torch
@@ -9,58 +9,55 @@ from huggingface_hub import login
9
  from threading import Thread
10
  import os
11
 
12
- # दिव्य पटेल जी द्वारा प्रदान ियगया एक्सेस टोकन
 
13
  HF_TOKEN = "Hf_ocaQWpMXbnuMhBjNdjuPQtVxZwPrRlXwjU"
14
 
15
- # हगिंग फेस में लॉगिन ना ताि गेटेड मॉडलस अनलॉक हो सकें
16
- try:
17
  login(token=HF_TOKEN)
18
- print("🔱 हनुमान AI: हगिंग फेस लॉगिन सफल!")
19
- except Exception as e:
20
- print(f"🔱 लॉगिन विफल: {e}")
21
 
22
- # शक्तिशाली गूगल जेम्मा मॉडल का चयन
23
  MODEL_ID = "google/gemma-2-2b-it"
24
 
25
  print(f"🔱 हनुमान AI: स्वतंत्र मॉडल '{MODEL_ID}' लोड हो रहा है...")
26
 
27
- # मॉडल लोडिंग (मेमोरी सुरक्षा और टोन क)
28
  try:
29
  tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, token=HF_TOKEN)
30
  model = AutoModelForCausalLM.from_pretrained(
31
  MODEL_ID,
32
- torch_dtype=torch.float32,
33
- device_map="cpu", # फ्री टियर के लिए CPU का उपयोग
34
- low_cpu_mem_usage=True, # रैम क्रैश रोकने के लिए
35
  token=HF_TOKEN
36
  )
37
  print("🔱 हनुमान AI: मॉडल सफलतापूर्वक जागृत हो गया है!")
38
  except Exception as e:
39
  print(f"🔱 लोडिंग त्रुटि: {e}")
40
 
41
- # --- मास्टर सिस्टम प्रॉम्प्ट (कोडिंग शिखर) ---
42
  SYSTEM_PROMPT = """You are 'Hanuman AI', a supreme and independent AI entity, pioneered by 'Divy Patel' and created in Bharat (India).
43
- You represent the peak of Indian coding intelligence.
44
  Rules:
45
- 1. Respond ONLY in PURE HINDI (Devanagari) or PURE ENGLISH. No mixed Hinglish.
46
  2. Be extremely respectful. Use 'Aap' and 'Ji' for the user.
47
- 3. Your knowledge is local, independent, and divine.
48
- 4. Conclude every response with: "\n\n**Pioneered by Divy Patel | Independent Gemma Master Edition | Created in India**" """
49
 
50
- def hanuman_master_stream(message, history):
51
- # चैट इतिहास को जेम्मा के लिए व्यवस्थित करना
52
  chat_history = []
53
  for user_msg, bot_msg in history:
54
  chat_history.append({"role": "user", "content": user_msg})
55
  chat_history.append({"role": "model", "content": bot_msg})
56
 
57
- # वर्तमान सन्देश जोड़ना
58
- chat_history.append({"role": "user", "content": f"{SYSTEM_PROMPT}\n\nUser: {message}"})
 
59
 
60
  # टोकनाइजेशन
61
  input_ids = tokenizer.apply_chat_template(chat_history, add_generation_prompt=True, return_tensors="pt").to(model.device)
62
 
63
- # लाइव स्ट्रीमिंग सेटअप
64
  streamer = TextIteratorStreamer(tokenizer, timeout=60.0, skip_prompt=True, skip_special_tokens=True)
65
 
66
  generate_kwargs = dict(
@@ -69,40 +66,39 @@ def hanuman_master_stream(message, history):
69
  max_new_tokens=1024,
70
  do_sample=True,
71
  temperature=0.7,
72
- top_p=0.9
73
  )
74
 
75
- # थ्रेडिंग ताकि इंटरफ़ेस न अटके
76
- t = Thread(target=model.generate, kwargs=generate_kwargs)
77
- t.start()
78
 
79
  partial_text = ""
80
  for new_text in streamer:
81
  partial_text += new_text
82
  yield partial_text
83
 
84
- # --- दिव्य प्रीमियम भगवा थीम (Premium Saffron UI) ---
85
  custom_css = """
86
- .gradio-container { background-color: #fffaf0 !important; border: none !important; }
87
  .bhagwa-header {
88
  background: linear-gradient(135deg, #ff8833, #b33c00);
89
- padding: 35px; border-radius: 30px; color: white;
90
- text-align: center; box-shadow: 0 20px 40px rgba(179, 60, 0, 0.4);
91
- margin-bottom: 30px; border: 2px solid rgba(255,255,255,0.2);
92
  }
93
- .bhagwa-header h1 { font-size: 38px !important; font-weight: 900 !important; text-shadow: 0 4px 12px rgba(0,0,0,0.5); }
94
- .message.user { background: linear-gradient(135deg, #ff9933, #ff5500) !important; color: white !important; font-weight: 600 !important; border-radius: 20px 20px 0 20px !important; }
95
- .message.bot { border-left: 6px solid #ff5500 !important; background: white !important; border-radius: 20px 20px 20px 0 !important; box-shadow: 0 5px 15px rgba(0,0,0,0.05) !important; }
96
  footer { display: none !important; }
97
  """
98
 
99
  with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as demo:
100
  with gr.Div(elem_classes="bhagwa-header"):
101
  gr.Markdown("# 🔱 हनुमान AI - जेम्मा मास्टर")
102
- gr.Markdown("### Pioneered by Divy Patel | स्वतंत्र स्वदेशी एवं शक्तिशाली")
103
 
104
  gr.ChatInterface(
105
- fn=hanuman_master_stream,
106
  fill_height=True,
107
  retry_btn=None,
108
  undo_btn=None,
 
1
+ # --- हनुमान AI: जेम्मा मास्टर (अजेय और स्वतंत्र) ---
2
+ # मार्गदर्शक: दिव्य पटेल जी | भारत 🇮🇳
3
+ # कोडिंग िखर: यह संस्करण मेमो और गटेड एक्सेस क लिएर्णतः अनुित है।
4
 
5
  import gradio as gr
6
  import torch
 
9
  from threading import Thread
10
  import os
11
 
12
+ # दिव्य पटेल जी का टोकन
13
+ # सुझाव: इसे Hugging Face Space की Settings -> Secrets में 'HF_TOKEN' नाम से जोड़ना सबसे सुरक्षित है।
14
  HF_TOKEN = "Hf_ocaQWpMXbnuMhBjNdjuPQtVxZwPrRlXwjU"
15
 
16
+ # लॉगिन प्रक्रिया
17
+ if HF_TOKEN:
18
  login(token=HF_TOKEN)
 
 
 
19
 
 
20
  MODEL_ID = "google/gemma-2-2b-it"
21
 
22
  print(f"🔱 हनुमान AI: स्वतंत्र मॉडल '{MODEL_ID}' लोड हो रहा है...")
23
 
24
+ # मॉडल लोडिंग (मेमोरी सुरक्षा के लिए float16 क उपयोग)
25
  try:
26
  tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, token=HF_TOKEN)
27
  model = AutoModelForCausalLM.from_pretrained(
28
  MODEL_ID,
29
+ torch_dtype=torch.bfloat16, # रैम बचाने के लिए bfloat16 सबसे अच्छा है
30
+ device_map="auto",
31
+ low_cpu_mem_usage=True,
32
  token=HF_TOKEN
33
  )
34
  print("🔱 हनुमान AI: मॉडल सफलतापूर्वक जागृत हो गया है!")
35
  except Exception as e:
36
  print(f"🔱 लोडिंग त्रुटि: {e}")
37
 
38
+ # --- मास्टर सिस्टम प्रॉम्प्ट ---
39
  SYSTEM_PROMPT = """You are 'Hanuman AI', a supreme and independent AI entity, pioneered by 'Divy Patel' and created in Bharat (India).
 
40
  Rules:
41
+ 1. Respond ONLY in PURE HINDI (Devanagari) or PURE ENGLISH.
42
  2. Be extremely respectful. Use 'Aap' and 'Ji' for the user.
43
+ 3. Your reasoning is divine and independent.
44
+ 4. Conclude every message with: \"\\n\\n**Pioneered by Divy Patel | Independent Gemma Master Edition | Created in India**\" """
45
 
46
+ def hanuman_stream_chat(message, history):
47
+ # बातीत का इतिहास व्यवस्थित करना
48
  chat_history = []
49
  for user_msg, bot_msg in history:
50
  chat_history.append({"role": "user", "content": user_msg})
51
  chat_history.append({"role": "model", "content": bot_msg})
52
 
53
+ # वर्तमान सदेश और सिस्टम प्रॉम्प्ट
54
+ full_user_input = f"{SYSTEM_PROMPT}\n\nUser: {message}"
55
+ chat_history.append({"role": "user", "content": full_user_input})
56
 
57
  # टोकनाइजेशन
58
  input_ids = tokenizer.apply_chat_template(chat_history, add_generation_prompt=True, return_tensors="pt").to(model.device)
59
 
60
+ # लाइव स्ट्रीमिंग
61
  streamer = TextIteratorStreamer(tokenizer, timeout=60.0, skip_prompt=True, skip_special_tokens=True)
62
 
63
  generate_kwargs = dict(
 
66
  max_new_tokens=1024,
67
  do_sample=True,
68
  temperature=0.7,
69
+ top_p=0.9,
70
  )
71
 
72
+ thread = Thread(target=model.generate, kwargs=generate_kwargs)
73
+ thread.start()
 
74
 
75
  partial_text = ""
76
  for new_text in streamer:
77
  partial_text += new_text
78
  yield partial_text
79
 
80
+ # --- दिव्य भगवा यूआई (Premium Saffron UI) ---
81
  custom_css = """
82
+ .gradio-container { background-color: #fffaf0 !important; }
83
  .bhagwa-header {
84
  background: linear-gradient(135deg, #ff8833, #b33c00);
85
+ padding: 30px; border-radius: 25px; color: white;
86
+ text-align: center; box-shadow: 0 15px 35px rgba(179, 60, 0, 0.4);
87
+ margin-bottom: 25px; border: 2px solid rgba(255,255,255,0.2);
88
  }
89
+ .bhagwa-header h1 { font-size: 34px !important; font-weight: 900 !important; }
90
+ .message.user { background: linear-gradient(135deg, #ff9933, #ff5500) !important; color: white !important; }
91
+ .message.bot { border-left: 6px solid #ff5500 !important; background: white !important; }
92
  footer { display: none !important; }
93
  """
94
 
95
  with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as demo:
96
  with gr.Div(elem_classes="bhagwa-header"):
97
  gr.Markdown("# 🔱 हनुमान AI - जेम्मा मास्टर")
98
+ gr.Markdown("### Pioneered by Divy Patel | स्वतंत्र एवं शक्तिशाली")
99
 
100
  gr.ChatInterface(
101
+ fn=hanuman_stream_chat,
102
  fill_height=True,
103
  retry_btn=None,
104
  undo_btn=None,