|
import gradio as gr |
|
from transformers.agents import CodeAgent, ReactCodeAgent, ReactJsonAgent, load_tool |
|
import random |
|
|
|
|
|
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! π" |
|
|
|
|
|
tools = [WittyQuoteTool(), MLDevTool()] |
|
try: |
|
tools.append(load_tool("speech_to_text")) |
|
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) |
|
|
|
|
|
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() |