Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,80 +1,91 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from gradio_client import Client
|
| 3 |
import os
|
|
|
|
| 4 |
|
| 5 |
-
# ह
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
"""
|
| 8 |
-
|
| 9 |
-
यह फाइल्स और टेक्स्ट के लिए 'None' की स्थिति को संभालता है।
|
| 10 |
"""
|
| 11 |
try:
|
| 12 |
-
# क्रेडिओ क्लाइंट
|
| 13 |
-
client = Client(
|
| 14 |
|
| 15 |
-
# १. सिस्टम प्रॉम्प्ट को लागू करना (apply_prompt)
|
| 16 |
-
|
| 17 |
-
client.predict(
|
| 18 |
-
input_value=system_prompt,
|
| 19 |
-
api_name="/apply_prompt"
|
| 20 |
-
)
|
| 21 |
|
| 22 |
-
# २. पे
|
| 23 |
-
# यदि टेक्स्ट
|
| 24 |
-
final_text =
|
| 25 |
-
final_files =
|
| 26 |
|
| 27 |
-
# प
|
| 28 |
-
|
| 29 |
-
|
| 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 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
except Exception as e:
|
| 50 |
-
|
| 51 |
|
| 52 |
-
#
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 62 |
-
lines=
|
| 63 |
)
|
| 64 |
-
|
| 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=
|
| 69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
-
#
|
| 72 |
submit_btn.click(
|
| 73 |
-
fn=
|
| 74 |
-
inputs=[
|
| 75 |
-
outputs=
|
| 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()
|