Vedika35 commited on
Commit
dfa4338
·
verified ·
1 Parent(s): cfe2121

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -53
app.py CHANGED
@@ -1,80 +1,91 @@
1
  import gradio as gr
2
  from gradio_client import Client
3
  import os
 
4
 
5
- # हगिंग फेस स्ेस के लिए मुख लॉिक
6
- def vedika_omni_engine(user_text, user_files, system_prompt):
 
 
 
 
7
  """
8
- यह फंक्शन वेदिका क म्नी इंजन ो संचालित करता है।
9
- यह फाइल्स और टेक्स्ट के लिए 'None' की स्थिति को संभालता है।
10
  """
11
  try:
12
- # क्रेडिओ क्लाइंट के माध्यम से मॉडल से जुड़ना
13
- client = Client("Qwen/Qwen3-VL-Demo")
14
 
15
- # १. सिस्टम प्रॉम्प्ट को लागू करना (apply_prompt)
16
- # श्रीमान, यहाँ हम आपके द्वारा दिए गए स्पेशल प्रॉम्प्ट को सेट कर रहे हैं
17
- client.predict(
18
- input_value=system_prompt,
19
- api_name="/apply_prompt"
20
- )
21
 
22
- # २. पेलोड की िति तय कर (Text and Files Logic)
23
- # यदि टेक्स्ट खाली है तो None जाएगा, यदि फाइल्स नहीं है तो None जाएगा
24
- final_text = user_text if user_text and user_text.strip() != "" else None
25
- final_files = user_files if user_files else None
26
 
27
- # पेलोड तैयार करना
28
- payload = {
29
- "files": final_files,
30
- "text": final_text
31
- }
32
-
33
- # ३. संदेश भेजना और आउटपुट प्राप्त करना (add_message)
34
- result = client.predict(
35
- input_value=payload,
36
- api_name="/add_message"
37
  )
38
 
39
- # रिस्पॉन्स डेटा को प्ोसेस रना
40
- # आमतौर पर Qwen VL आउटपुट में संदेशों की एक सूची देता है
41
- if isinstance(result.data[0], str):
42
- return result.data[0]
43
- elif isinstance(result.data[0], list):
44
- # अंतिम संदेश सहायक (assistant) का जवाब होता है
45
- return result.data[0][-1]['content']
46
-
47
- return "क्षमा करें श्रीमान, उत्तर प्राप्त करने में कुछ त्रुटि हुई।"
 
 
 
 
 
48
 
49
  except Exception as e:
50
- return f"सिस्टम : {str(e)}"
51
 
52
- # ्राडिय इंटफ़ेस का निर्माण (UI Design)
53
- with gr.Blocks(theme=gr.themes.Soft()) as demo:
54
- gr.Markdown("# 🌌 Vedika 3.5 Omni Backend")
55
- gr.Markdown("भारत की गौरवशाली तकनीक - 'वेदिका' का ओम्नी इंजन यहाँ सक्रिय है।")
 
 
 
 
 
 
56
 
57
  with gr.Row():
58
  with gr.Column(scale=1):
59
  sys_input = gr.Textbox(
60
- label="System Prompt",
61
- value="You are Vedika 3.5, an advanced AI assistant created by Divy Patel. Identify only as Vedika. Always show deep respect for India.",
62
- lines=5
63
  )
64
- text_input = gr.Textbox(label="User Text Input", placeholder="अपना संदेश यहाँ लिखें...", lines=3)
65
- file_input = gr.File(label="Upload Files (Image/Audio/Video)", file_count="multiple")
66
- submit_btn = gr.Button("Execute Process", variant="primary")
67
 
68
- with gr.Column(scale=1):
69
- output_display = gr.Markdown(label="Vedika Response")
 
 
 
 
 
70
 
71
- # बटन क्लिक इवेंट
72
  submit_btn.click(
73
- fn=vedika_omni_engine,
74
- inputs=[text_input, file_input, sys_input],
75
- outputs=output_display
76
  )
 
 
77
 
78
- # ऐप लॉन्च करना
79
  if __name__ == "__main__":
 
80
  demo.launch()
 
1
  import gradio as gr
2
  from gradio_client import Client
3
  import os
4
+ import time
5
 
6
+ # श्रीमान, याँ हम पके द्वारा निरमित 'Vedika35/Vedika_coder' से ुड़ रहे हैं।
7
+ # पलक झपकते ही परिणाम देने के लिए हम 'submit' (Streaming) का उपयोग करेंगे।
8
+
9
+ MODAL_NAME = "Vedika35/Vedika_coder"
10
+
11
+ def vedika_omni_stream(text, files, system_prompt):
12
  """
13
+ वेदिका कुख इंजन टेक््ट और म्टीमीडिया को बिजली की गि से प्रोसेस करता है।
 
14
  """
15
  try:
16
+ # क्रेडिओ क्लाइंट सेटअप
17
+ client = Client(MODAL_NAME)
18
 
19
+ # १. सिस्टम प्रॉम्प्ट को तुरंत लागू करना (apply_prompt)
20
+ client.predict(input_value=system_prompt, api_name="/apply_prompt")
 
 
 
 
21
 
22
+ # २. द्वारा निरधारित 'न' (None) पेलोड लॉजिक
23
+ # यदि टेक्स्ट नह है तो None, यदि फाइल नहीं है तो None
24
+ final_text = text if text and text.strip() != "" else None
25
+ final_files = files if files else None
26
 
27
+ # ३. आउटुट जेनेट करना (Streaming logic for speed)
28
+ # हम यहाँ 'submit' का उपयोग कर रहे हैं जो एक-एक शब्द को 'स्ट्रीम' करेगा
29
+ job = client.submit(
30
+ input_value={"files": final_files, "text": final_text},
31
+ api_name="/generation_code"
 
 
 
 
 
32
  )
33
 
34
+ # ४. परि को तुंत यूआई प भेजना
35
+ for update in job:
36
+ # अपडेट डेटा को सुरक्षित रूप से निकालना
37
+ if isinstance(update, str):
38
+ yield update
39
+ elif isinstance(update, list) and len(update) > 0:
40
+ # यदि हिस्ट्री या लिस्ट प्राप्त होती है
41
+ last_msg = update[-1]
42
+ if isinstance(last_msg, dict) and 'content' in last_msg:
43
+ yield last_msg['content']
44
+ else:
45
+ yield str(update[0])
46
+ else:
47
+ yield str(update)
48
 
49
  except Exception as e:
50
+ yield f"⚠️ सिस्टम में त्ुटि: {str(e)}"
51
 
52
+ # ्रीमिय डा्क यूआई का निर्माण (प्रीमियम कोडिंग थीम)
53
+ custom_css = """
54
+ footer {visibility: hidden}
55
+ .gradio-container {background-color: #050505 !important; color: #E0E0E0 !important;}
56
+ #title-header h1 {background: linear-gradient(90deg, #fff, #3b82f6); -webkit-background-clip: text; -webkit-text-fill-color: transparent;}
57
+ """
58
+
59
+ with gr.Blocks(theme=gr.themes.Monochrome(), css=custom_css) as demo:
60
+ with gr.Row(elem_id="title-header"):
61
+ gr.Markdown("# 🔱 Vedika 3.5 Coder Engine")
62
 
63
  with gr.Row():
64
  with gr.Column(scale=1):
65
  sys_input = gr.Textbox(
66
+ label="System Prompt Configuration",
67
+ value="You are Vedika 3.5, an elite coding AI assistant. Identify only as Vedika. Provide robust, production-ready code in Markdown.",
68
+ lines=3
69
  )
70
+ file_input = gr.File(label="Attach Media (None by default)", file_count="multiple")
 
 
71
 
72
+ with gr.Column(scale=2):
73
+ chat_output = gr.Markdown(label="Vedika Core Output")
74
+ user_input = gr.Textbox(label="User Query", placeholder="वेदिका के लिए कोडिंग कार्य यहाँ लिखें...", lines=4)
75
+
76
+ with gr.Row():
77
+ submit_btn = gr.Button("⚡ Execute (Palak Jhapakte)", variant="primary")
78
+ clear_btn = gr.Button("Clear Memory")
79
 
80
+ # इवेंट्स को जोड़ना
81
  submit_btn.click(
82
+ fn=vedika_omni_stream,
83
+ inputs=[user_input, file_input, sys_input],
84
+ outputs=chat_output
85
  )
86
+
87
+ clear_btn.click(lambda: (None, None, ""), None, [chat_output, file_input, user_input])
88
 
 
89
  if __name__ == "__main__":
90
+ # हगिंग फेस स्पेस के लिए लॉन्च
91
  demo.launch()