awacke1's picture
Update app.py
3b51c72 verified
raw
history blame
3.21 kB
import gradio as gr
from transformers.agents import CodeAgent, ReactCodeAgent, ReactJsonAgent, load_tool
import random
# Custom tools since some built-ins are flaky
class WittyQuoteTool:
def __init__(self):
self.name = "witty_quote"
self.description = "Spouts a random witty ML quote! πŸ˜‚"
self.inputs = {}
self.output_type = str
def __call__(self):
quotes = ["'AI is just spicy statistics' - Unknown πŸ€“", "'The only limit is your GPU budget' - Me πŸ’Έ"]
return random.choice(quotes)
class MLDevTool:
def __init__(self):
self.name = "ml_dev_helper"
self.description = "Helps with ML dev tasks like coding or debugging! πŸ› οΈ"
self.inputs = {"task": {"type": "str", "description": "What ML task to assist with"}}
self.output_type = str
def __call__(self, task):
return f"🧠 Beep boop! Helping with: {task}. Tip: Always check your data first! πŸ“Š"
# Initialize 9 agents with stable tools
tools = [WittyQuoteTool(), MLDevTool()] # Dropped problematic built-ins
try:
tools.append(load_tool("speech_to_text")) # Safer built-in option
except Exception as e:
print(f"Skipping speech_to_text due to: {e}")
agents = {
"CodeWizard": CodeAgent(tools=tools, system_prompt="You're a coding genius! πŸ§™β€β™‚οΈ Write concise code."),
"StepByStep": ReactCodeAgent(tools=tools, system_prompt="Think step-by-step, oh wise one! πŸ€–"),
"JsonJester": ReactJsonAgent(tools=tools, system_prompt="JSON all the things! πŸ˜‚"),
"DataDiva": ReactCodeAgent(tools=tools, system_prompt="Clean that data, superstar! 🌟"),
"ModelMaestro": CodeAgent(tools=tools, system_prompt="Tune models like a pro! 🎻"),
"DebugDemon": ReactJsonAgent(tools=tools, system_prompt="Squash bugs with flair! πŸ‘Ύ"),
"DocDynamo": ReactCodeAgent(tools=tools, system_prompt="Write docs that dazzle! πŸ“œ"),
"VizVirtuoso": CodeAgent(tools=tools, system_prompt="Visualize like a boss! πŸ“ˆ"),
"DeployDaredevil": ReactJsonAgent(tools=tools, system_prompt="Deploy with guts! πŸš€"),
}
def run_ml_team(task):
outputs = []
for name, agent in agents.items():
try:
if isinstance(agent, CodeAgent):
result = agent.run(task, return_generated_code=True)
outputs.append(f"πŸŽ‰ {name} says: Here's my code magic! ```python\n{result}\n```")
else:
result = agent.run(task)
outputs.append(f"πŸ”₯ {name} reacts: {result}")
except Exception as e:
outputs.append(f"😱 {name} tripped over a wire: {str(e)}")
return "\n\n".join(outputs)
# Gradio UI
with gr.Blocks(title="ML Agent Party πŸŽ‰") as demo:
gr.Markdown("# ML Agent Party! πŸ€–πŸŽˆ\n9 Agents to Boost Your ML Game with Sass & Smarts!")
task_input = gr.Textbox(label="What's Your ML Quest? πŸ—‘οΈ", placeholder="E.g., 'Clean my data!'")
output = gr.Markdown(label="Agent Squad Response 🎀")
submit_btn = gr.Button("Unleash the Crew! πŸš€")
submit_btn.click(run_ml_team, inputs=task_input, outputs=output)
gr.Markdown("---\nBuilt with ❀️ & πŸ˜‚ by xAI's Grok & Transformers Agents")
demo.launch()