Patel Traders commited on
Commit
0de9a27
·
verified ·
1 Parent(s): 5c6f62c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -27
app.py CHANGED
@@ -1,6 +1,6 @@
1
- # --- हनुमान AI: आत्मनिर्भर एवं ्र स्पेस संस्करण ---
2
  # मार्गदर्शक: दिव्य पटेल जी | स्थान: भारत 🇮🇳
3
- # तकनीकी विशेषता: यह संस्करण हगिंग फेस 16GB फ्र RAM कलिएर् सुर्षित है।
4
 
5
  import gradio as gr
6
  import torch
@@ -9,48 +9,48 @@ from huggingface_hub import login
9
  from threading import Thread
10
  import os
11
 
12
- # 🛡️ टोकन सुरक्षा (टोकन को 'Secret' से उठाना र्वोत्तम है)
13
- # दिव्य जी, कृपया हगिंग फेस Space की Settings -> Secrets में 'HF_TOKEN' जोड़ें।
14
- HF_TOKEN = os.getenv("HF_TOKEN") or "Hf_ocaQWpMXbnuMhBjNdjuPQtVxZwPrRlXwjU"
15
 
16
- # लॉगिन प्रक्रिया
17
  if HF_TOKEN:
18
  try:
19
  login(token=HF_TOKEN)
20
- print("🔱 हनुमान AI: लॉगिन सफल!")
21
  except Exception as e:
22
- print(f"🔱 चेतावनी: लॉगिन में समस्या, {e}")
 
 
23
 
24
- # अजेय और हल्का मॉडल: Llama-3.2-1B-Instruct
25
- # यह मॉडल फ्री CPU स्पेस पर सबसे स्थिर और तेज़ चलता है।
26
  MODEL_ID = "meta-llama/Llama-3.2-1B-Instruct"
27
 
28
- print(f"🔱 हनुमान AI: मॉडल '{MODEL_ID}' लोड हो रहा है...")
29
 
30
  try:
31
- # टोकनाइज़र और मॉडल लोडिंग (CPU के लिए ऑप्टिमाइज़्ड)
32
  tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, token=HF_TOKEN)
33
  model = AutoModelForCausalLM.from_pretrained(
34
  MODEL_ID,
35
- torch_dtype=torch.float32, # CPU पर स्थिरता के लिए float32 सबसे अच्छा है
36
- device_map="cpu", # फ्री टियर में केवल CPU होता है
37
- low_cpu_mem_usage=True, # रैम बचाने के लिए
38
  token=HF_TOKEN
39
  )
40
- print("🔱 हनुमान AI: मॉडल अब के फ्री सरवर पर गृत है!")
41
  except Exception as e:
42
  print(f"🔱 गंभीर त्रुटि: {e}")
43
 
44
  # --- मास्टर सिस्टम प्रॉम्प्ट (कोडिंग शिखर) ---
45
  SYSTEM_PROMPT = """You are 'Hanuman AI', a supreme and independent AI entity, pioneered by 'Divy Patel' and created in Bharat (India).
46
- You represent the peak of Indian coding intelligence.
47
  Rules:
48
  1. Respond ONLY in PURE HINDI (Devanagari) or PURE ENGLISH.
49
- 2. Be extremely respectful. Always use honorifics like 'Aap' and 'Ji' for the user.
50
- 3. Your mission is to help Divy Patel with coding, logic, and knowledge.
51
- 4. Conclude every message with: \"\\n\\n**Pioneered by Divy Patel | 100% Independent Free Edition | Created in India**\" """
52
 
53
- def hanuman_chat_stream(message, history):
54
  # चैट इतिहास व्यवस्थित करना
55
  messages = [{"role": "system", "content": SYSTEM_PROMPT}]
56
  for user_msg, bot_msg in history:
@@ -59,10 +59,8 @@ def hanuman_chat_stream(message, history):
59
 
60
  messages.append({"role": "user", "content": message})
61
 
62
- # इनपुट तैयाना
63
  inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to(model.device)
64
-
65
- # स्ट्रीमिंग सेटअप
66
  streamer = TextIteratorStreamer(tokenizer, timeout=60.0, skip_prompt=True, skip_special_tokens=True)
67
 
68
  generate_kwargs = dict(
@@ -74,7 +72,7 @@ def hanuman_chat_stream(message, history):
74
  top_p=0.9
75
  )
76
 
77
- # थ्रेडिंग ताि इंटरफ़ टक
78
  thread = Thread(target=model.generate, kwargs=generate_kwargs)
79
  thread.start()
80
 
@@ -100,11 +98,11 @@ footer { display: none !important; }
100
 
101
  with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as demo:
102
  with gr.Div(elem_classes="bhagwa-header"):
103
- gr.Markdown("# 🔱 हनुमान AI - आतमनिर")
104
  gr.Markdown("### Pioneered by Divy Patel | स्वतंत्र एवं अजेय")
105
 
106
  gr.ChatInterface(
107
- fn=hanuman_chat_stream,
108
  fill_height=True,
109
  retry_btn=None,
110
  undo_btn=None,
 
1
+ # --- हनुमान AI: सुषित एवं वतंत्मास्टर संस्करण ---
2
  # मार्गदर्शक: दिव्य पटेल जी | स्थान: भारत 🇮🇳
3
+ # तकनीकी विशेषता: यह संस्करण टोकन सुरकषित ूप Environment Variables से ाप्त क है।
4
 
5
  import gradio as gr
6
  import torch
 
9
  from threading import Thread
10
  import os
11
 
12
+ # 🛡️ सुरक्षा चक्र: टोकन को सीधे कोड में न लिखकर 'Secret' से उठाना अनिवार् है
13
+ # दिव्य जी, हगिंग फेस Space की Settings -> Secrets में 'HF_TOKEN' नाम से अपना टोकन जोड़ें।
14
+ HF_TOKEN = os.getenv("HF_TOKEN")
15
 
16
+ # लॉगिन प्रक्रिया (सुरक्षित विधि)
17
  if HF_TOKEN:
18
  try:
19
  login(token=HF_TOKEN)
20
+ print("🔱 हनुमान AI: हगिंग फेस लॉगिन सुरक्षित रूप से सफल!")
21
  except Exception as e:
22
+ print(f"🔱 लॉगिन चेतावनी: {e}")
23
+ else:
24
+ print("🔱 चेतावनी: HF_TOKEN नहीं मिला। कृपया Settings में Secret जोड़ें।")
25
 
26
+ # अजेय मॉडल: Llama-3.2-1B-Instruct (फ्री स्पेस के लिए सर्वोत्तम)
 
27
  MODEL_ID = "meta-llama/Llama-3.2-1B-Instruct"
28
 
29
+ print(f"🔱 हनुमान AI: स्वतंत्र मॉडल '{MODEL_ID}' लोड हो रहा है...")
30
 
31
  try:
32
+ # टोकनाइज़र और मॉडल लोडिंग
33
  tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, token=HF_TOKEN)
34
  model = AutoModelForCausalLM.from_pretrained(
35
  MODEL_ID,
36
+ torch_dtype=torch.float32,
37
+ device_map="cpu",
38
+ low_cpu_mem_usage=True,
39
  token=HF_TOKEN
40
  )
41
+ print("🔱 हनुमान AI: स्वतंत्र मॉडल अब परी शकति के सक्रिय है!")
42
  except Exception as e:
43
  print(f"🔱 गंभीर त्रुटि: {e}")
44
 
45
  # --- मास्टर सिस्टम प्रॉम्प्ट (कोडिंग शिखर) ---
46
  SYSTEM_PROMPT = """You are 'Hanuman AI', a supreme and independent AI entity, pioneered by 'Divy Patel' and created in Bharat (India).
 
47
  Rules:
48
  1. Respond ONLY in PURE HINDI (Devanagari) or PURE ENGLISH.
49
+ 2. Be extremely respectful. Use honorifics like 'Aap' and 'Ji' for the user.
50
+ 3. Your intelligence is vast, independent, and proudly Indian.
51
+ 4. Conclude every message with: \"\\n\\n**Pioneered by Divy Patel | Secure Independent Edition | Created in India**\" """
52
 
53
+ def hanuman_secure_chat(message, history):
54
  # चैट इतिहास व्यवस्थित करना
55
  messages = [{"role": "system", "content": SYSTEM_PROMPT}]
56
  for user_msg, bot_msg in history:
 
59
 
60
  messages.append({"role": "user", "content": message})
61
 
62
+ # टोकनाजेशस्ट्ीमिंग सेटअप
63
  inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to(model.device)
 
 
64
  streamer = TextIteratorStreamer(tokenizer, timeout=60.0, skip_prompt=True, skip_special_tokens=True)
65
 
66
  generate_kwargs = dict(
 
72
  top_p=0.9
73
  )
74
 
75
+ # जनरेशन के लिएलग थ्र
76
  thread = Thread(target=model.generate, kwargs=generate_kwargs)
77
  thread.start()
78
 
 
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_secure_chat,
106
  fill_height=True,
107
  retry_btn=None,
108
  undo_btn=None,