CodedAgent1 / app.py
MandyDeep's picture
Create app.py
610d0f4 verified
raw
history blame
2.51 kB
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()