File size: 2,508 Bytes
610d0f4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import gradio as gr
from smolagents import CodeAgent, InferenceClientModel

# Set up the free serverless models via Hugging Face's infrastructure
# These run on high-end remote GPUs for free, bypass CPU slowdowns
models_dictionary = {
    "DeepSeek-R1 (Reasoning)": InferenceClientModel(model_id="deepseek-ai/DeepSeek-R1"),
    "Qwen 2.5 (General Expert)": InferenceClientModel(model_id="Qwen/Qwen2.5-72B-Instruct"),
    "Llama 3.3 (Fast Text)": InferenceClientModel(model_id="meta-llama/Llama-3.3-70B-Instruct")
}

def ask_all_agents(user_prompt, uploaded_image):
    responses = {}
    
    # Process text/image input structure safely
    if uploaded_image:
        # Construct multimodal input payload for vision-capable endpoints
        content = [
            {"type": "text", "text": user_prompt if user_prompt else "Analyze this image."},
            {"type": "image_url", "image_url": {"url": uploaded_image}}
        ]
    else:
        content = user_prompt

    for name, model in models_dictionary.items():
        try:
            # Create a localized agent wrapper
            agent = CodeAgent(tools=[], model=model)
            # Execute request safely
            result = agent.run(content)
            responses[name] = str(result)
        except Exception as e:
            responses[name] = f"Could not process: {str(e)}"
            
    return (
        responses["DeepSeek-R1 (Reasoning)"],
        responses["Qwen 2.5 (General Expert)"],
        responses["Llama 3.3 (Fast Text)"]
    )

# Build a responsive UI optimized for mobile viewports
with gr.Blocks(theme=gr.themes.Soft()) as demo:
    gr.Markdown("# πŸ“± Mobile Omni-Agent Dashboard")
    gr.Markdown("Submit one prompt to query multiple open-source engines simultaneously.")
    
    with gr.Row():
        with gr.Column():
            text_input = gr.Textbox(label="Your Prompt", placeholder="Type your query here...", lines=3)
            image_input = gr.Image(label="Upload Image (Optional)", type="filepath")
            submit_btn = gr.Button("πŸš€ Trigger Synchronized Generation", variant="primary")
            
    with gr.Row():
        out_deepseek = gr.Textbox(label="🧠 DeepSeek-R1 Output", lines=5)
        out_qwen = gr.Textbox(label="πŸ‘‘ Qwen 2.5 Output", lines=5)
        out_llama = gr.Textbox(label="πŸ¦™ Llama 3.3 Output", lines=5)

    submit_btn.click(
        fn=ask_all_agents,
        inputs=[text_input, image_input],
        outputs=[out_deepseek, out_qwen, out_llama]
    )

demo.launch()