MandyDeep commited on
Commit
610d0f4
·
verified ·
1 Parent(s): a4bec71

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -0
app.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from smolagents import CodeAgent, InferenceClientModel
3
+
4
+ # Set up the free serverless models via Hugging Face's infrastructure
5
+ # These run on high-end remote GPUs for free, bypass CPU slowdowns
6
+ models_dictionary = {
7
+ "DeepSeek-R1 (Reasoning)": InferenceClientModel(model_id="deepseek-ai/DeepSeek-R1"),
8
+ "Qwen 2.5 (General Expert)": InferenceClientModel(model_id="Qwen/Qwen2.5-72B-Instruct"),
9
+ "Llama 3.3 (Fast Text)": InferenceClientModel(model_id="meta-llama/Llama-3.3-70B-Instruct")
10
+ }
11
+
12
+ def ask_all_agents(user_prompt, uploaded_image):
13
+ responses = {}
14
+
15
+ # Process text/image input structure safely
16
+ if uploaded_image:
17
+ # Construct multimodal input payload for vision-capable endpoints
18
+ content = [
19
+ {"type": "text", "text": user_prompt if user_prompt else "Analyze this image."},
20
+ {"type": "image_url", "image_url": {"url": uploaded_image}}
21
+ ]
22
+ else:
23
+ content = user_prompt
24
+
25
+ for name, model in models_dictionary.items():
26
+ try:
27
+ # Create a localized agent wrapper
28
+ agent = CodeAgent(tools=[], model=model)
29
+ # Execute request safely
30
+ result = agent.run(content)
31
+ responses[name] = str(result)
32
+ except Exception as e:
33
+ responses[name] = f"Could not process: {str(e)}"
34
+
35
+ return (
36
+ responses["DeepSeek-R1 (Reasoning)"],
37
+ responses["Qwen 2.5 (General Expert)"],
38
+ responses["Llama 3.3 (Fast Text)"]
39
+ )
40
+
41
+ # Build a responsive UI optimized for mobile viewports
42
+ with gr.Blocks(theme=gr.themes.Soft()) as demo:
43
+ gr.Markdown("# 📱 Mobile Omni-Agent Dashboard")
44
+ gr.Markdown("Submit one prompt to query multiple open-source engines simultaneously.")
45
+
46
+ with gr.Row():
47
+ with gr.Column():
48
+ text_input = gr.Textbox(label="Your Prompt", placeholder="Type your query here...", lines=3)
49
+ image_input = gr.Image(label="Upload Image (Optional)", type="filepath")
50
+ submit_btn = gr.Button("🚀 Trigger Synchronized Generation", variant="primary")
51
+
52
+ with gr.Row():
53
+ out_deepseek = gr.Textbox(label="🧠 DeepSeek-R1 Output", lines=5)
54
+ out_qwen = gr.Textbox(label="👑 Qwen 2.5 Output", lines=5)
55
+ out_llama = gr.Textbox(label="🦙 Llama 3.3 Output", lines=5)
56
+
57
+ submit_btn.click(
58
+ fn=ask_all_agents,
59
+ inputs=[text_input, image_input],
60
+ outputs=[out_deepseek, out_qwen, out_llama]
61
+ )
62
+
63
+ demo.launch()