Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,112 +1,69 @@
|
|
1 |
-
import
|
2 |
-
import os
|
3 |
-
import glob
|
4 |
-
import re
|
5 |
-
import base64
|
6 |
-
import pytz
|
7 |
-
from datetime import datetime
|
8 |
from transformers.agents import CodeAgent, ReactCodeAgent, ReactJsonAgent, load_tool
|
|
|
9 |
|
10 |
-
#
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
4. π― Lean core
|
18 |
-
5. π§ Shareable memory
|
19 |
-
6. π€ Personalized
|
20 |
-
7. π¦ Cloneable brevity
|
21 |
-
""")
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
"CodeCrafter": CodeAgent(tools=tools, system_prompt="Craft code like a pro! π₯οΈ"),
|
27 |
-
"StepSage": ReactCodeAgent(tools=tools, system_prompt="Step-by-step wisdom! π§ "),
|
28 |
-
"JsonJugger": ReactJsonAgent(tools=tools, system_prompt="JSON-powered antics! π€‘"),
|
29 |
-
"OutlineOracle": ReactCodeAgent(tools=tools, system_prompt="Outline everything! π"),
|
30 |
-
"ToolTitan": CodeAgent(tools=tools, system_prompt="List tools with swagger! π§"),
|
31 |
-
"SpecSpinner": ReactJsonAgent(tools=tools, system_prompt="Spin specs with style! π"),
|
32 |
-
"ImageImp": CodeAgent(tools=tools, system_prompt="Dream up image prompts! π¨"),
|
33 |
-
"VisualVortex": ReactCodeAgent(tools=tools, system_prompt="Generate visuals! πΌοΈ"),
|
34 |
-
"GlossGuru": ReactJsonAgent(tools=tools, system_prompt="Define terms with pizzazz! π"),
|
35 |
-
}
|
36 |
-
|
37 |
-
# MoE Prompts mapped to agents
|
38 |
-
moe_prompts = {
|
39 |
-
"Create a python streamlit app.py...": "CodeCrafter",
|
40 |
-
"Create a python gradio app.py...": "CodeCrafter",
|
41 |
-
"Create a mermaid model...": "OutlineOracle",
|
42 |
-
"Create a top three list of tools...": "ToolTitan",
|
43 |
-
"Create a specification in markdown...": "SpecSpinner",
|
44 |
-
"Create an image generation prompt...": "ImageImp",
|
45 |
-
"Generate an image which describes...": "VisualVortex",
|
46 |
-
"List top ten glossary terms...": "GlossGuru",
|
47 |
-
"": "StepSage" # Default agent for blank selection
|
48 |
-
}
|
49 |
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
st.session_state.files = []
|
57 |
|
58 |
-
|
59 |
-
|
60 |
-
selected_moe = st.selectbox("Pick an MoE Adventure! π²", moe_options, index=0, key="selected_moe")
|
61 |
|
62 |
-
#
|
63 |
-
|
64 |
-
|
|
|
|
|
|
|
65 |
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
def run_agent(task, agent_name):
|
79 |
-
agent = agents[agent_name]
|
80 |
-
if isinstance(agent, CodeAgent):
|
81 |
-
return agent.run(task, return_generated_code=True)
|
82 |
-
return agent.run(task)
|
83 |
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
query = st.text_input("Ask Away! π€", placeholder="E.g., 'Explain transformers!'")
|
88 |
-
|
89 |
-
if query:
|
90 |
-
agent_name = moe_prompts[selected_moe]
|
91 |
try:
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
|
|
97 |
except Exception as e:
|
98 |
-
|
|
|
99 |
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
with open(st.session_state.selected_file, 'r') as f:
|
109 |
-
st.markdown(f.read())
|
110 |
|
111 |
-
|
112 |
-
main()
|
|
|
1 |
+
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
from transformers.agents import CodeAgent, ReactCodeAgent, ReactJsonAgent, load_tool
|
3 |
+
import random
|
4 |
|
5 |
+
# Custom tools since some built-ins are flaky
|
6 |
+
class WittyQuoteTool:
|
7 |
+
def __init__(self):
|
8 |
+
self.name = "witty_quote"
|
9 |
+
self.description = "Spouts a random witty ML quote! π"
|
10 |
+
self.inputs = {}
|
11 |
+
self.output_type = str
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
+
def __call__(self):
|
14 |
+
quotes = ["'AI is just spicy statistics' - Unknown π€", "'The only limit is your GPU budget' - Me πΈ"]
|
15 |
+
return random.choice(quotes)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
+
class MLDevTool:
|
18 |
+
def __init__(self):
|
19 |
+
self.name = "ml_dev_helper"
|
20 |
+
self.description = "Helps with ML dev tasks like coding or debugging! π οΈ"
|
21 |
+
self.inputs = {"task": {"type": "str", "description": "What ML task to assist with"}}
|
22 |
+
self.output_type = str
|
|
|
23 |
|
24 |
+
def __call__(self, task):
|
25 |
+
return f"π§ Beep boop! Helping with: {task}. Tip: Always check your data first! π"
|
|
|
26 |
|
27 |
+
# Initialize 9 agents with stable tools
|
28 |
+
tools = [WittyQuoteTool(), MLDevTool()] # Dropped problematic built-ins
|
29 |
+
try:
|
30 |
+
tools.append(load_tool("speech_to_text")) # Safer built-in option
|
31 |
+
except Exception as e:
|
32 |
+
print(f"Skipping speech_to_text due to: {e}")
|
33 |
|
34 |
+
agents = {
|
35 |
+
"CodeWizard": CodeAgent(tools=tools, system_prompt="You're a coding genius! π§ββοΈ Write concise code."),
|
36 |
+
"StepByStep": ReactCodeAgent(tools=tools, system_prompt="Think step-by-step, oh wise one! π€"),
|
37 |
+
"JsonJester": ReactJsonAgent(tools=tools, system_prompt="JSON all the things! π"),
|
38 |
+
"DataDiva": ReactCodeAgent(tools=tools, system_prompt="Clean that data, superstar! π"),
|
39 |
+
"ModelMaestro": CodeAgent(tools=tools, system_prompt="Tune models like a pro! π»"),
|
40 |
+
"DebugDemon": ReactJsonAgent(tools=tools, system_prompt="Squash bugs with flair! πΎ"),
|
41 |
+
"DocDynamo": ReactCodeAgent(tools=tools, system_prompt="Write docs that dazzle! π"),
|
42 |
+
"VizVirtuoso": CodeAgent(tools=tools, system_prompt="Visualize like a boss! π"),
|
43 |
+
"DeployDaredevil": ReactJsonAgent(tools=tools, system_prompt="Deploy with guts! π"),
|
44 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
|
46 |
+
def run_ml_team(task):
|
47 |
+
outputs = []
|
48 |
+
for name, agent in agents.items():
|
|
|
|
|
|
|
|
|
49 |
try:
|
50 |
+
if isinstance(agent, CodeAgent):
|
51 |
+
result = agent.run(task, return_generated_code=True)
|
52 |
+
outputs.append(f"π {name} says: Here's my code magic! ```python\n{result}\n```")
|
53 |
+
else:
|
54 |
+
result = agent.run(task)
|
55 |
+
outputs.append(f"π₯ {name} reacts: {result}")
|
56 |
except Exception as e:
|
57 |
+
outputs.append(f"π± {name} tripped over a wire: {str(e)}")
|
58 |
+
return "\n\n".join(outputs)
|
59 |
|
60 |
+
# Gradio UI
|
61 |
+
with gr.Blocks(title="ML Agent Party π") as demo:
|
62 |
+
gr.Markdown("# ML Agent Party! π€π\n9 Agents to Boost Your ML Game with Sass & Smarts!")
|
63 |
+
task_input = gr.Textbox(label="What's Your ML Quest? π‘οΈ", placeholder="E.g., 'Clean my data!'")
|
64 |
+
output = gr.Markdown(label="Agent Squad Response π€")
|
65 |
+
submit_btn = gr.Button("Unleash the Crew! π")
|
66 |
+
submit_btn.click(run_ml_team, inputs=task_input, outputs=output)
|
67 |
+
gr.Markdown("---\nBuilt with β€οΈ & π by xAI's Grok & Transformers Agents")
|
|
|
|
|
68 |
|
69 |
+
demo.launch()
|
|