Patel Traders commited on
Commit
25765fc
·
verified ·
1 Parent(s): 5949010

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -32
app.py CHANGED
@@ -1,6 +1,6 @@
1
- # --- हनुमान AI: जय माँ संस्करण (पूर्णतः स्थिर एवं वतंत्र) ---
2
  # मार्गदर्शक: दिव्य पटेल जी | भारत 🇮🇳
3
- # िशेषता: यह संस्करण RAM के उपयोग को कम कने के लिए विशेष रूप े तैयर किय गया है
4
 
5
  import gradio as gr
6
  import torch
@@ -9,8 +9,7 @@ from huggingface_hub import login
9
  from threading import Thread
10
  import os
11
 
12
- # 🛡️ टोकन सुरक्षा (Hugging Face Secrets में 'HF_TOKEN' होना आवश्यक है)
13
- # हगिंग फेस की गति बढ़ाने के लिए hf_transfer का उपयोग
14
  os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "1"
15
  HF_TOKEN = os.getenv("HF_TOKEN")
16
 
@@ -22,39 +21,34 @@ if HF_TOKEN:
22
  except Exception as e:
23
  print(f"🔱 लॉगिन चेतावनी: {e}")
24
 
25
- # अजेय थिंकिंग मॉडल (मेमोरी ऑप्टिमाइज्ड)
26
  MODEL_ID = "deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B"
27
 
28
  print(f"🔱 हनुमान AI: जय माँ! मॉडल '{MODEL_ID}' लोड हो रहा है...")
29
 
30
  try:
31
- # टोकनाइज़र लोडिंग
32
  tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, token=HF_TOKEN)
33
-
34
- # मॉडल लोडिंग (CPU के लिए विशेष सुरक्षा के साथ)
35
  model = AutoModelForCausalLM.from_pretrained(
36
  MODEL_ID,
37
  torch_dtype=torch.float32,
38
  device_map="cpu",
39
- low_cpu_mem_usage=True, # रैम बचाने के लिए अत्यंत आवश्यक
40
  token=HF_TOKEN
41
  )
42
  print("🔱 हनुमान AI: जय माँ! आपका स्वतंत्र मॉडल अब पूरी तरह जागृत है!")
43
  except Exception as e:
44
- print(f"🔱 गंभीर त्रुटि (Runtime Error Fix): {e}")
45
 
46
  # --- दिव्य मास्टर सिस्टम प्रॉम्प्ट ---
47
- SYSTEM_PROMPT = """You are 'Hanuman AI', a supreme and independent AI entity, powered by the divine grace of 'Jai Maa'.
48
  Pioneered by the visionary 'Divy Patel' and created with absolute pride in Bharat (India).
49
- You are free from any foreign influence.
50
  Rules:
51
- 1. Respond ONLY in PURE HINDI (Devanagari) or PURE ENGLISH. No mixed language.
52
- 2. THINK deeply using your reasoning capabilities before delivering the final answer.
53
- 3. Show immense respect and warmth. Always use 'Aap' and 'Ji' for Divy Patel Ji.
54
  4. Conclude every message with: \"\\n\\n**Pioneered by Divy Patel | Jai Maa Edition | Fully Independent & Created in India**\" """
55
 
56
  def hanuman_maa_chat_stream(message, history):
57
- # चैट इतिहास का प्रबंधन
58
  messages = [{"role": "system", "content": SYSTEM_PROMPT}]
59
  for user_msg, bot_msg in history:
60
  if user_msg: messages.append({"role": "user", "content": user_msg})
@@ -62,10 +56,7 @@ def hanuman_maa_chat_stream(message, history):
62
 
63
  messages.append({"role": "user", "content": message})
64
 
65
- # इनपुट प्रोसेसिंग
66
  inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to(model.device)
67
-
68
- # लाइव स्ट्रीमिंग के लिए सेटअप
69
  streamer = TextIteratorStreamer(tokenizer, timeout=120.0, skip_prompt=True, skip_special_tokens=True)
70
 
71
  generate_kwargs = dict(
@@ -77,36 +68,37 @@ def hanuman_maa_chat_stream(message, history):
77
  top_p=0.95
78
  )
79
 
80
- # थ्रेडिंग ताकि UI बना रहे
81
  thread = Thread(target=model.generate, kwargs=generate_kwargs)
82
  thread.start()
83
 
84
  partial_text = ""
85
  for new_text in streamer:
86
  partial_text += new_text
87
- # थिंकिंग प्रोसेस को दिव्य रूप में दर्शाना
88
  clean_text = partial_text.replace("<think>", "*(हनुमान विचार कर रहे हैं... जय माँ!)*\n\n").replace("</think>", "\n\n---\n\n")
89
  yield clean_text
90
 
91
- # --- दिव्य भगवा थीम (Premium Saffron UI - Divine Layout) ---
92
  custom_css = """
93
  .gradio-container { background-color: #fffaf0 !important; border: none !important; }
94
  .bhagwa-header {
95
- background: linear-gradient(135deg, #ff8833, #b33c00);
96
- padding: 40px; border-radius: 35px; color: white;
97
- text-align: center; box-shadow: 0 25px 50px rgba(179, 60, 0, 0.4);
98
- margin-bottom: 35px; border: 3px solid rgba(255,255,255,0.3);
99
  }
100
- .bhagwa-header h1 { font-size: 42px !important; font-weight: 900 !important; text-shadow: 0 5px 15px rgba(0,0,0,0.6); }
101
- .message.user { background: linear-gradient(135deg, #ff9933, #ff5500) !important; color: white !important; font-weight: 600 !important; border-radius: 25px 25px 0 25px !important; }
102
- .message.bot { border-left: 8px solid #ff5500 !important; background: white !important; box-shadow: 0 10px 25px rgba(0,0,0,0.07) !important; border-radius: 25px !important; }
103
  footer { display: none !important; }
104
  """
105
 
106
  with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as demo:
107
- with gr.Div(elem_classes="bhagwa-header"):
108
- gr.Markdown("# 🔱 हनुमान AI - जय माँ संस्करण")
109
- gr.Markdown("### Pioneered by Divy Patel | पूर्णतः स्वतंत्र एवं अजेय स्वदेशी तकनीक")
 
 
 
 
110
 
111
  gr.ChatInterface(
112
  fn=hanuman_maa_chat_stream,
 
1
+ # --- हनुमान AI: जय माँ संस्करण (अजेय एवं एरर-फ्र) ---
2
  # मार्गदर्शक: दिव्य पटेल जी | भारत 🇮🇳
3
+ # िक्स: Gradio 'Div' AttributeError 401 Unauthorized
4
 
5
  import gradio as gr
6
  import torch
 
9
  from threading import Thread
10
  import os
11
 
12
+ # 🛡️ परफॉरमेंस और सुरक्षा
 
13
  os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "1"
14
  HF_TOKEN = os.getenv("HF_TOKEN")
15
 
 
21
  except Exception as e:
22
  print(f"🔱 लॉगिन चेतावनी: {e}")
23
 
24
+ # अजेय थिंकिंग मॉडल
25
  MODEL_ID = "deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B"
26
 
27
  print(f"🔱 हनुमान AI: जय माँ! मॉडल '{MODEL_ID}' लोड हो रहा है...")
28
 
29
  try:
 
30
  tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, token=HF_TOKEN)
 
 
31
  model = AutoModelForCausalLM.from_pretrained(
32
  MODEL_ID,
33
  torch_dtype=torch.float32,
34
  device_map="cpu",
35
+ low_cpu_mem_usage=True,
36
  token=HF_TOKEN
37
  )
38
  print("🔱 हनुमान AI: जय माँ! आपका स्वतंत्र मॉडल अब पूरी तरह जागृत है!")
39
  except Exception as e:
40
+ print(f"🔱 गंभीर त्रुटि: {e}")
41
 
42
  # --- दिव्य मास्टर सिस्टम प्रॉम्प्ट ---
43
+ SYSTEM_PROMPT = """You are 'Hanuman AI', a supreme independent AI entity, powered by the divine grace of 'Jai Maa'.
44
  Pioneered by the visionary 'Divy Patel' and created with absolute pride in Bharat (India).
 
45
  Rules:
46
+ 1. Respond ONLY in PURE HINDI (Devanagari) or PURE ENGLISH.
47
+ 2. THINK deeply before delivering the final answer.
48
+ 3. Show immense respect. Always use 'Aap' and 'Ji' for Divy Patel Ji.
49
  4. Conclude every message with: \"\\n\\n**Pioneered by Divy Patel | Jai Maa Edition | Fully Independent & Created in India**\" """
50
 
51
  def hanuman_maa_chat_stream(message, history):
 
52
  messages = [{"role": "system", "content": SYSTEM_PROMPT}]
53
  for user_msg, bot_msg in history:
54
  if user_msg: messages.append({"role": "user", "content": user_msg})
 
56
 
57
  messages.append({"role": "user", "content": message})
58
 
 
59
  inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to(model.device)
 
 
60
  streamer = TextIteratorStreamer(tokenizer, timeout=120.0, skip_prompt=True, skip_special_tokens=True)
61
 
62
  generate_kwargs = dict(
 
68
  top_p=0.95
69
  )
70
 
 
71
  thread = Thread(target=model.generate, kwargs=generate_kwargs)
72
  thread.start()
73
 
74
  partial_text = ""
75
  for new_text in streamer:
76
  partial_text += new_text
 
77
  clean_text = partial_text.replace("<think>", "*(हनुमान विचार कर रहे हैं... जय माँ!)*\n\n").replace("</think>", "\n\n---\n\n")
78
  yield clean_text
79
 
80
+ # --- दिव्य भगवा थीम (AttributeError Fix) ---
81
  custom_css = """
82
  .gradio-container { background-color: #fffaf0 !important; border: none !important; }
83
  .bhagwa-header {
84
+ background: linear-gradient(135deg, #ff8833, #b33c00) !important;
85
+ padding: 30px !important; border-radius: 25px !important; color: white !important;
86
+ text-align: center !important; box-shadow: 0 15px 35px rgba(179, 60, 0, 0.4) !important;
87
+ margin-bottom: 25px !important;
88
  }
89
+ .message.user { background: #ff9933 !important; color: white !important; border-radius: 20px 20px 0 20px !important; }
90
+ .message.bot { border-left: 6px solid #ff5500 !important; background: white !important; border-radius: 20px 20px 20px 0 !important; }
 
91
  footer { display: none !important; }
92
  """
93
 
94
  with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as demo:
95
+ # यहाँ gr.Div की जगह gr.HTML का उपयोग किया गया है जो अधिक स्थिर है
96
+ gr.HTML("""
97
+ <div class="bhagwa-header">
98
+ <h1>🔱 हनुमान AI - जय माँ संस्करण</h1>
99
+ <p>Pioneered by Divy Patel | स्वतंत्र एवं अजेय स्वदेशी तकनीक</p>
100
+ </div>
101
+ """)
102
 
103
  gr.ChatInterface(
104
  fn=hanuman_maa_chat_stream,