Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,102 +1,82 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from
|
| 3 |
-
import torch
|
| 4 |
from concurrent.futures import ThreadPoolExecutor, as_completed
|
| 5 |
-
import json
|
| 6 |
import time
|
| 7 |
from datetime import datetime
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
-
# Configuration for different agent types
|
| 10 |
AGENT_CONFIGS = {
|
| 11 |
"researcher": {
|
| 12 |
-
"model": "
|
| 13 |
"role": "Research and gather information",
|
| 14 |
-
"
|
| 15 |
},
|
| 16 |
"coder": {
|
| 17 |
-
"model": "
|
| 18 |
"role": "Generate and explain code",
|
| 19 |
-
"
|
| 20 |
},
|
| 21 |
"analyzer": {
|
| 22 |
-
"model": "
|
| 23 |
"role": "Analyze data and provide insights",
|
| 24 |
-
"
|
| 25 |
},
|
| 26 |
"writer": {
|
| 27 |
-
"model": "
|
| 28 |
"role": "Create content and documentation",
|
| 29 |
-
"
|
| 30 |
}
|
| 31 |
}
|
| 32 |
|
| 33 |
class AgentSystem:
|
| 34 |
def __init__(self):
|
| 35 |
-
|
| 36 |
-
self.
|
| 37 |
self.executor = ThreadPoolExecutor(max_workers=4)
|
| 38 |
-
self.device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 39 |
-
print(f"Using device: {self.device}")
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
self.models[agent_name] = AutoModelForCausalLM.from_pretrained(
|
| 48 |
-
model_name,
|
| 49 |
-
torch_dtype=torch.float16 if self.device == "cuda" else torch.float32,
|
| 50 |
-
low_cpu_mem_usage=True,
|
| 51 |
-
device_map="auto" if self.device == "cuda" else None
|
| 52 |
-
)
|
| 53 |
-
print(f"{agent_name} model loaded successfully!")
|
| 54 |
-
except Exception as e:
|
| 55 |
-
print(f"Error loading {agent_name} model: {e}")
|
| 56 |
-
# Fallback to smaller model
|
| 57 |
-
print(f"Falling back to distilgpt2 for {agent_name}")
|
| 58 |
-
self.tokenizers[agent_name] = AutoTokenizer.from_pretrained("distilgpt2")
|
| 59 |
-
self.models[agent_name] = AutoModelForCausalLM.from_pretrained("distilgpt2")
|
| 60 |
|
| 61 |
-
def generate_response(self, agent_name,
|
| 62 |
-
"""Generate response
|
| 63 |
try:
|
| 64 |
config = AGENT_CONFIGS[agent_name]
|
| 65 |
-
|
| 66 |
|
| 67 |
-
#
|
| 68 |
-
|
| 69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
inputs = inputs.to("cuda")
|
| 82 |
-
|
| 83 |
-
# Generate
|
| 84 |
-
with torch.no_grad():
|
| 85 |
-
outputs = model.generate(
|
| 86 |
-
inputs.input_ids,
|
| 87 |
-
max_length=max_length,
|
| 88 |
-
temperature=0.7,
|
| 89 |
-
top_p=0.9,
|
| 90 |
-
do_sample=True,
|
| 91 |
-
pad_token_id=tokenizer.eos_token_id
|
| 92 |
-
)
|
| 93 |
-
|
| 94 |
-
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 95 |
|
| 96 |
return {
|
| 97 |
"agent": agent_name,
|
| 98 |
"role": config["role"],
|
| 99 |
-
"response":
|
| 100 |
"status": "success"
|
| 101 |
}
|
| 102 |
|
|
@@ -108,7 +88,7 @@ class AgentSystem:
|
|
| 108 |
"status": "error"
|
| 109 |
}
|
| 110 |
|
| 111 |
-
def run_agents_parallel(self, task, selected_agents,
|
| 112 |
"""Run multiple agents in parallel"""
|
| 113 |
start_time = time.time()
|
| 114 |
futures = {}
|
|
@@ -120,7 +100,7 @@ class AgentSystem:
|
|
| 120 |
self.generate_response,
|
| 121 |
agent_name,
|
| 122 |
task,
|
| 123 |
-
|
| 124 |
)
|
| 125 |
futures[future] = agent_name
|
| 126 |
|
|
@@ -128,14 +108,14 @@ class AgentSystem:
|
|
| 128 |
for future in as_completed(futures):
|
| 129 |
agent_name = futures[future]
|
| 130 |
try:
|
| 131 |
-
result = future.result()
|
| 132 |
result["time_taken"] = round(time.time() - start_time, 2)
|
| 133 |
results.append(result)
|
| 134 |
except Exception as e:
|
| 135 |
results.append({
|
| 136 |
"agent": agent_name,
|
| 137 |
"role": AGENT_CONFIGS[agent_name]["role"],
|
| 138 |
-
"response": f"
|
| 139 |
"status": "error",
|
| 140 |
"time_taken": round(time.time() - start_time, 2)
|
| 141 |
})
|
|
@@ -144,13 +124,14 @@ class AgentSystem:
|
|
| 144 |
return results, total_time
|
| 145 |
|
| 146 |
# Initialize the agent system
|
| 147 |
-
print("Initializing AI Agent System...")
|
| 148 |
agent_system = AgentSystem()
|
|
|
|
| 149 |
|
| 150 |
-
def process_task(task, researcher, coder, analyzer, writer,
|
| 151 |
"""Process task with selected agents"""
|
| 152 |
if not task.strip():
|
| 153 |
-
return "Please enter a task!", ""
|
| 154 |
|
| 155 |
# Determine which agents to use
|
| 156 |
selected_agents = []
|
|
@@ -164,10 +145,14 @@ def process_task(task, researcher, coder, analyzer, writer, max_length):
|
|
| 164 |
selected_agents.append("writer")
|
| 165 |
|
| 166 |
if not selected_agents:
|
| 167 |
-
return "Please select at least one agent!", ""
|
|
|
|
|
|
|
| 168 |
|
| 169 |
# Run agents in parallel
|
| 170 |
-
results, total_time = agent_system.run_agents_parallel(task, selected_agents,
|
|
|
|
|
|
|
| 171 |
|
| 172 |
# Format output
|
| 173 |
output = f"# π€ AI Agent System Results\n\n"
|
|
@@ -176,119 +161,192 @@ def process_task(task, researcher, coder, analyzer, writer, max_length):
|
|
| 176 |
output += f"**Total Time:** {total_time}s\n\n"
|
| 177 |
output += "---\n\n"
|
| 178 |
|
| 179 |
-
for result in results:
|
| 180 |
status_emoji = "β
" if result["status"] == "success" else "β"
|
| 181 |
-
output += f"## {status_emoji} {result['agent'].upper()}
|
| 182 |
output += f"**Role:** {result['role']}\n\n"
|
| 183 |
-
output += f"**Response:**\n
|
| 184 |
-
output += f"*Completed in {result['time_taken']}s*\n\n"
|
| 185 |
output += "---\n\n"
|
| 186 |
|
| 187 |
-
# Create summary
|
| 188 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 189 |
"task": task,
|
| 190 |
-
"agents_used":
|
| 191 |
"total_time": total_time,
|
| 192 |
-
"timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
|
|
| 193 |
}
|
| 194 |
|
| 195 |
-
|
|
|
|
|
|
|
|
|
|
| 196 |
|
| 197 |
# Create Gradio Interface
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 209 |
|
| 210 |
with gr.Row():
|
| 211 |
with gr.Column(scale=1):
|
| 212 |
-
gr.Markdown("###
|
|
|
|
| 213 |
task_input = gr.Textbox(
|
| 214 |
-
label="
|
| 215 |
-
placeholder="Example:
|
| 216 |
-
lines=
|
| 217 |
)
|
| 218 |
|
| 219 |
-
gr.Markdown("### π― Select
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 224 |
|
| 225 |
-
|
| 226 |
minimum=100,
|
| 227 |
maximum=500,
|
| 228 |
-
value=
|
| 229 |
step=50,
|
| 230 |
-
label="
|
| 231 |
-
info="Tokens per agent"
|
| 232 |
)
|
| 233 |
|
| 234 |
-
process_btn = gr.Button(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 235 |
|
| 236 |
-
gr.Markdown(
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
-
|
| 240 |
-
- Agents run simultaneously for faster processing
|
| 241 |
- Each agent brings unique expertise
|
| 242 |
-
|
| 243 |
-
)
|
| 244 |
|
| 245 |
with gr.Column(scale=2):
|
| 246 |
-
gr.Markdown("###
|
| 247 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 248 |
|
| 249 |
-
with gr.Accordion("
|
| 250 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 251 |
|
| 252 |
-
gr.Markdown("### π Example Tasks")
|
| 253 |
gr.Examples(
|
| 254 |
examples=[
|
| 255 |
-
["Create a REST API for
|
| 256 |
-
["Build a machine learning
|
| 257 |
-
["Design a
|
| 258 |
-
["
|
| 259 |
-
["
|
| 260 |
],
|
| 261 |
inputs=task_input
|
| 262 |
)
|
| 263 |
|
| 264 |
-
gr.Markdown(
|
| 265 |
-
"""
|
| 266 |
---
|
| 267 |
|
| 268 |
## ποΈ System Architecture
|
| 269 |
|
| 270 |
-
|
| 271 |
-
- **Free Models**: Using Hugging Face hosted models (Zephyr-7B, CodeGen)
|
| 272 |
-
- **Specialized Agents**: Each agent has a specific role and expertise
|
| 273 |
-
- **Fault Tolerant**: Continues even if one agent fails
|
| 274 |
|
| 275 |
-
|
|
|
|
|
|
|
|
|
|
| 276 |
|
| 277 |
-
|
| 278 |
-
-
|
| 279 |
-
-
|
| 280 |
-
-
|
| 281 |
-
|
| 282 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 283 |
|
| 284 |
-
# Connect button
|
| 285 |
process_btn.click(
|
| 286 |
fn=process_task,
|
| 287 |
-
inputs=[
|
| 288 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 289 |
)
|
| 290 |
|
| 291 |
-
# Launch
|
| 292 |
if __name__ == "__main__":
|
| 293 |
-
demo.queue() #
|
| 294 |
-
demo.launch(
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from huggingface_hub import InferenceClient
|
|
|
|
| 3 |
from concurrent.futures import ThreadPoolExecutor, as_completed
|
|
|
|
| 4 |
import time
|
| 5 |
from datetime import datetime
|
| 6 |
+
import os
|
| 7 |
+
|
| 8 |
+
# Use Hugging Face Inference API (no model loading needed!)
|
| 9 |
+
# This is FREE and much faster!
|
| 10 |
|
|
|
|
| 11 |
AGENT_CONFIGS = {
|
| 12 |
"researcher": {
|
| 13 |
+
"model": "mistralai/Mistral-7B-Instruct-v0.2",
|
| 14 |
"role": "Research and gather information",
|
| 15 |
+
"system_prompt": "You are a research agent specialized in gathering and analyzing information. Provide detailed, well-researched responses."
|
| 16 |
},
|
| 17 |
"coder": {
|
| 18 |
+
"model": "bigcode/starcoder2-15b",
|
| 19 |
"role": "Generate and explain code",
|
| 20 |
+
"system_prompt": "You are an expert programmer. Generate clean, efficient, well-commented code."
|
| 21 |
},
|
| 22 |
"analyzer": {
|
| 23 |
+
"model": "mistralai/Mistral-7B-Instruct-v0.2",
|
| 24 |
"role": "Analyze data and provide insights",
|
| 25 |
+
"system_prompt": "You are a data analyst. Provide clear insights and actionable recommendations."
|
| 26 |
},
|
| 27 |
"writer": {
|
| 28 |
+
"model": "mistralai/Mistral-7B-Instruct-v0.2",
|
| 29 |
"role": "Create content and documentation",
|
| 30 |
+
"system_prompt": "You are a technical writer. Create clear, professional documentation and content."
|
| 31 |
}
|
| 32 |
}
|
| 33 |
|
| 34 |
class AgentSystem:
|
| 35 |
def __init__(self):
|
| 36 |
+
# No model loading! Using HF Inference API
|
| 37 |
+
self.clients = {}
|
| 38 |
self.executor = ThreadPoolExecutor(max_workers=4)
|
|
|
|
|
|
|
| 39 |
|
| 40 |
+
# Initialize inference clients for each agent
|
| 41 |
+
for agent_name in AGENT_CONFIGS.keys():
|
| 42 |
+
model = AGENT_CONFIGS[agent_name]["model"]
|
| 43 |
+
self.clients[agent_name] = InferenceClient(model=model)
|
| 44 |
+
|
| 45 |
+
print("β
Agent system initialized with Inference API!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
+
def generate_response(self, agent_name, task, max_tokens=300):
|
| 48 |
+
"""Generate response using HF Inference API"""
|
| 49 |
try:
|
| 50 |
config = AGENT_CONFIGS[agent_name]
|
| 51 |
+
client = self.clients[agent_name]
|
| 52 |
|
| 53 |
+
# Create prompt
|
| 54 |
+
messages = [
|
| 55 |
+
{
|
| 56 |
+
"role": "system",
|
| 57 |
+
"content": config["system_prompt"]
|
| 58 |
+
},
|
| 59 |
+
{
|
| 60 |
+
"role": "user",
|
| 61 |
+
"content": f"Task: {task}"
|
| 62 |
+
}
|
| 63 |
+
]
|
| 64 |
|
| 65 |
+
# Generate response
|
| 66 |
+
response_text = ""
|
| 67 |
+
for message in client.chat_completion(
|
| 68 |
+
messages=messages,
|
| 69 |
+
max_tokens=max_tokens,
|
| 70 |
+
temperature=0.7,
|
| 71 |
+
stream=True
|
| 72 |
+
):
|
| 73 |
+
if hasattr(message.choices[0].delta, 'content'):
|
| 74 |
+
response_text += message.choices[0].delta.content
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
return {
|
| 77 |
"agent": agent_name,
|
| 78 |
"role": config["role"],
|
| 79 |
+
"response": response_text.strip(),
|
| 80 |
"status": "success"
|
| 81 |
}
|
| 82 |
|
|
|
|
| 88 |
"status": "error"
|
| 89 |
}
|
| 90 |
|
| 91 |
+
def run_agents_parallel(self, task, selected_agents, max_tokens=300):
|
| 92 |
"""Run multiple agents in parallel"""
|
| 93 |
start_time = time.time()
|
| 94 |
futures = {}
|
|
|
|
| 100 |
self.generate_response,
|
| 101 |
agent_name,
|
| 102 |
task,
|
| 103 |
+
max_tokens
|
| 104 |
)
|
| 105 |
futures[future] = agent_name
|
| 106 |
|
|
|
|
| 108 |
for future in as_completed(futures):
|
| 109 |
agent_name = futures[future]
|
| 110 |
try:
|
| 111 |
+
result = future.result(timeout=30) # 30 second timeout per agent
|
| 112 |
result["time_taken"] = round(time.time() - start_time, 2)
|
| 113 |
results.append(result)
|
| 114 |
except Exception as e:
|
| 115 |
results.append({
|
| 116 |
"agent": agent_name,
|
| 117 |
"role": AGENT_CONFIGS[agent_name]["role"],
|
| 118 |
+
"response": f"Timeout or error: {str(e)}",
|
| 119 |
"status": "error",
|
| 120 |
"time_taken": round(time.time() - start_time, 2)
|
| 121 |
})
|
|
|
|
| 124 |
return results, total_time
|
| 125 |
|
| 126 |
# Initialize the agent system
|
| 127 |
+
print("π Initializing AI Agent System...")
|
| 128 |
agent_system = AgentSystem()
|
| 129 |
+
print("β
System ready!")
|
| 130 |
|
| 131 |
+
def process_task(task, researcher, coder, analyzer, writer, max_tokens, progress=gr.Progress()):
|
| 132 |
"""Process task with selected agents"""
|
| 133 |
if not task.strip():
|
| 134 |
+
return "β οΈ Please enter a task!", "", ""
|
| 135 |
|
| 136 |
# Determine which agents to use
|
| 137 |
selected_agents = []
|
|
|
|
| 145 |
selected_agents.append("writer")
|
| 146 |
|
| 147 |
if not selected_agents:
|
| 148 |
+
return "β οΈ Please select at least one agent!", "", ""
|
| 149 |
+
|
| 150 |
+
progress(0, desc="Starting agents...")
|
| 151 |
|
| 152 |
# Run agents in parallel
|
| 153 |
+
results, total_time = agent_system.run_agents_parallel(task, selected_agents, max_tokens)
|
| 154 |
+
|
| 155 |
+
progress(1, desc="Complete!")
|
| 156 |
|
| 157 |
# Format output
|
| 158 |
output = f"# π€ AI Agent System Results\n\n"
|
|
|
|
| 161 |
output += f"**Total Time:** {total_time}s\n\n"
|
| 162 |
output += "---\n\n"
|
| 163 |
|
| 164 |
+
for idx, result in enumerate(results, 1):
|
| 165 |
status_emoji = "β
" if result["status"] == "success" else "β"
|
| 166 |
+
output += f"## {status_emoji} Agent {idx}: {result['agent'].upper()}\n\n"
|
| 167 |
output += f"**Role:** {result['role']}\n\n"
|
| 168 |
+
output += f"**Response:**\n\n{result['response']}\n\n"
|
| 169 |
+
output += f"*β±οΈ Completed in {result['time_taken']}s*\n\n"
|
| 170 |
output += "---\n\n"
|
| 171 |
|
| 172 |
+
# Create summary stats
|
| 173 |
+
success_count = sum(1 for r in results if r["status"] == "success")
|
| 174 |
+
stats = f"""π **Execution Stats**
|
| 175 |
+
- Total Agents: {len(selected_agents)}
|
| 176 |
+
- Successful: {success_count}
|
| 177 |
+
- Failed: {len(selected_agents) - success_count}
|
| 178 |
+
- Total Time: {total_time}s
|
| 179 |
+
- Average per Agent: {round(total_time / len(selected_agents), 2)}s
|
| 180 |
+
"""
|
| 181 |
+
|
| 182 |
+
# Detailed JSON for download
|
| 183 |
+
details = {
|
| 184 |
"task": task,
|
| 185 |
+
"agents_used": selected_agents,
|
| 186 |
"total_time": total_time,
|
| 187 |
+
"timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
| 188 |
+
"results": results
|
| 189 |
}
|
| 190 |
|
| 191 |
+
import json
|
| 192 |
+
json_output = json.dumps(details, indent=2)
|
| 193 |
+
|
| 194 |
+
return output, stats, json_output
|
| 195 |
|
| 196 |
# Create Gradio Interface
|
| 197 |
+
custom_css = """
|
| 198 |
+
.gradio-container {
|
| 199 |
+
font-family: 'Inter', sans-serif;
|
| 200 |
+
}
|
| 201 |
+
.main-header {
|
| 202 |
+
text-align: center;
|
| 203 |
+
padding: 20px;
|
| 204 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 205 |
+
color: white;
|
| 206 |
+
border-radius: 10px;
|
| 207 |
+
margin-bottom: 20px;
|
| 208 |
+
}
|
| 209 |
+
"""
|
| 210 |
+
|
| 211 |
+
with gr.Blocks(theme=gr.themes.Soft(), css=custom_css, title="AI Agent System") as demo:
|
| 212 |
+
gr.HTML("""
|
| 213 |
+
<div class="main-header">
|
| 214 |
+
<h1>π€ Multi-Agent AI System</h1>
|
| 215 |
+
<p>Parallel AI Processing with Specialized Agents | Powered by Hugging Face Inference API</p>
|
| 216 |
+
</div>
|
| 217 |
+
""")
|
| 218 |
|
| 219 |
with gr.Row():
|
| 220 |
with gr.Column(scale=1):
|
| 221 |
+
gr.Markdown("### π Task Configuration")
|
| 222 |
+
|
| 223 |
task_input = gr.Textbox(
|
| 224 |
+
label="What do you want the agents to work on?",
|
| 225 |
+
placeholder="Example: Build a user authentication system with JWT tokens",
|
| 226 |
+
lines=5
|
| 227 |
)
|
| 228 |
|
| 229 |
+
gr.Markdown("### π― Select Your Team")
|
| 230 |
+
|
| 231 |
+
with gr.Group():
|
| 232 |
+
researcher_check = gr.Checkbox(
|
| 233 |
+
label="π Researcher Agent",
|
| 234 |
+
value=True,
|
| 235 |
+
info="Gathers information and best practices"
|
| 236 |
+
)
|
| 237 |
+
coder_check = gr.Checkbox(
|
| 238 |
+
label="π» Coder Agent",
|
| 239 |
+
value=True,
|
| 240 |
+
info="Writes production-ready code"
|
| 241 |
+
)
|
| 242 |
+
analyzer_check = gr.Checkbox(
|
| 243 |
+
label="π Analyzer Agent",
|
| 244 |
+
value=True,
|
| 245 |
+
info="Provides insights and recommendations"
|
| 246 |
+
)
|
| 247 |
+
writer_check = gr.Checkbox(
|
| 248 |
+
label="βοΈ Writer Agent",
|
| 249 |
+
value=True,
|
| 250 |
+
info="Creates documentation"
|
| 251 |
+
)
|
| 252 |
+
|
| 253 |
+
gr.Markdown("### βοΈ Settings")
|
| 254 |
|
| 255 |
+
max_tokens = gr.Slider(
|
| 256 |
minimum=100,
|
| 257 |
maximum=500,
|
| 258 |
+
value=300,
|
| 259 |
step=50,
|
| 260 |
+
label="Response Length",
|
| 261 |
+
info="Tokens per agent response"
|
| 262 |
)
|
| 263 |
|
| 264 |
+
process_btn = gr.Button(
|
| 265 |
+
"π Deploy Agents",
|
| 266 |
+
variant="primary",
|
| 267 |
+
size="lg"
|
| 268 |
+
)
|
| 269 |
|
| 270 |
+
gr.Markdown("""
|
| 271 |
+
### π‘ Pro Tips
|
| 272 |
+
- Use all 4 agents for comprehensive results
|
| 273 |
+
- Agents run simultaneously = 3-4x faster!
|
|
|
|
| 274 |
- Each agent brings unique expertise
|
| 275 |
+
- No model downloads = instant startup
|
| 276 |
+
""")
|
| 277 |
|
| 278 |
with gr.Column(scale=2):
|
| 279 |
+
gr.Markdown("### π Results Dashboard")
|
| 280 |
+
|
| 281 |
+
output_display = gr.Markdown(
|
| 282 |
+
value="*Results will appear here after running agents...*",
|
| 283 |
+
label="Agent Outputs"
|
| 284 |
+
)
|
| 285 |
|
| 286 |
+
with gr.Accordion("π Execution Statistics", open=True):
|
| 287 |
+
stats_display = gr.Markdown(value="*No data yet*")
|
| 288 |
+
|
| 289 |
+
with gr.Accordion("πΎ Download Results (JSON)", open=False):
|
| 290 |
+
json_output = gr.Code(
|
| 291 |
+
label="Complete Results",
|
| 292 |
+
language="json",
|
| 293 |
+
lines=10
|
| 294 |
+
)
|
| 295 |
+
|
| 296 |
+
gr.Markdown("### π Quick Start Examples")
|
| 297 |
|
|
|
|
| 298 |
gr.Examples(
|
| 299 |
examples=[
|
| 300 |
+
["Create a REST API for a todo list application with authentication"],
|
| 301 |
+
["Build a machine learning pipeline for image classification"],
|
| 302 |
+
["Design a microservices architecture for an e-commerce platform"],
|
| 303 |
+
["Develop a real-time chat application using WebSockets"],
|
| 304 |
+
["Create a data visualization dashboard for sales analytics"],
|
| 305 |
],
|
| 306 |
inputs=task_input
|
| 307 |
)
|
| 308 |
|
| 309 |
+
gr.Markdown("""
|
|
|
|
| 310 |
---
|
| 311 |
|
| 312 |
## ποΈ System Architecture
|
| 313 |
|
| 314 |
+
**How It Works:**
|
|
|
|
|
|
|
|
|
|
| 315 |
|
| 316 |
+
1. **Task Distribution** β Your task is sent to selected agents
|
| 317 |
+
2. **Parallel Processing** β All agents work simultaneously (not sequential!)
|
| 318 |
+
3. **Smart Aggregation** β Results are collected as they complete
|
| 319 |
+
4. **Instant Results** β See output from each agent in real-time
|
| 320 |
|
| 321 |
+
**Technology:**
|
| 322 |
+
- β‘ Hugging Face Inference API (serverless, no model loading)
|
| 323 |
+
- π ThreadPoolExecutor for true parallelism
|
| 324 |
+
- π Free tier compatible
|
| 325 |
+
- π Real-time progress tracking
|
| 326 |
+
|
| 327 |
+
**Models Used:**
|
| 328 |
+
- Mistral-7B-Instruct (Researcher, Analyzer, Writer)
|
| 329 |
+
- StarCoder2-15B (Coder)
|
| 330 |
+
""")
|
| 331 |
|
| 332 |
+
# Connect button
|
| 333 |
process_btn.click(
|
| 334 |
fn=process_task,
|
| 335 |
+
inputs=[
|
| 336 |
+
task_input,
|
| 337 |
+
researcher_check,
|
| 338 |
+
coder_check,
|
| 339 |
+
analyzer_check,
|
| 340 |
+
writer_check,
|
| 341 |
+
max_tokens
|
| 342 |
+
],
|
| 343 |
+
outputs=[output_display, stats_display, json_output]
|
| 344 |
)
|
| 345 |
|
| 346 |
+
# Launch with optimized settings
|
| 347 |
if __name__ == "__main__":
|
| 348 |
+
demo.queue(max_size=20) # Handle multiple users
|
| 349 |
+
demo.launch(
|
| 350 |
+
show_error=True,
|
| 351 |
+
share=False
|
| 352 |
+
)
|