Spaces:
Runtime error
Runtime error
Charles Azam commited on
Commit ·
5978528
1
Parent(s): 5167047
feat: add model choice
Browse files
gradio_app.py
CHANGED
|
@@ -85,11 +85,11 @@ custom_css = """
|
|
| 85 |
}
|
| 86 |
|
| 87 |
.spinner {
|
| 88 |
-
border:
|
| 89 |
-
border-top:
|
| 90 |
border-radius: 50%;
|
| 91 |
-
width:
|
| 92 |
-
height:
|
| 93 |
animation: spin 1s linear infinite;
|
| 94 |
margin-right: 0.5rem;
|
| 95 |
}
|
|
@@ -112,18 +112,18 @@ custom_css = """
|
|
| 112 |
color: white !important;
|
| 113 |
border: none !important;
|
| 114 |
padding: 0.5rem 1.5rem !important;
|
| 115 |
-
border-radius:
|
| 116 |
font-weight: 600 !important;
|
| 117 |
font-size: 0.95rem !important;
|
| 118 |
transition: all 0.3s ease !important;
|
| 119 |
-
box-shadow: 0
|
| 120 |
-
min-width:
|
| 121 |
-
max-width:
|
| 122 |
}
|
| 123 |
|
| 124 |
.send-button:hover {
|
| 125 |
-
transform: translateY(-
|
| 126 |
-
box-shadow: 0
|
| 127 |
}
|
| 128 |
|
| 129 |
.send-button:disabled {
|
|
@@ -138,10 +138,10 @@ custom_css = """
|
|
| 138 |
line-height: 1.4;
|
| 139 |
color: var(--body-text-color);
|
| 140 |
background: var(--background-fill-secondary);
|
| 141 |
-
border:
|
| 142 |
-
border-radius:
|
| 143 |
padding: 1rem;
|
| 144 |
-
max-height:
|
| 145 |
overflow-y: auto;
|
| 146 |
}
|
| 147 |
|
|
@@ -213,6 +213,34 @@ custom_css = """
|
|
| 213 |
.dark .tool-description {
|
| 214 |
color: var(--body-text-color);
|
| 215 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 216 |
"""
|
| 217 |
|
| 218 |
def format_log_entry(log_text):
|
|
@@ -240,7 +268,7 @@ def format_log_entry(log_text):
|
|
| 240 |
|
| 241 |
return "".join(formatted_lines)
|
| 242 |
|
| 243 |
-
def run_agent_with_ui(user_input: str):
|
| 244 |
"""Enhanced agent runner with better UI feedback"""
|
| 245 |
if not user_input.strip():
|
| 246 |
return "", ""
|
|
@@ -250,7 +278,7 @@ def run_agent_with_ui(user_input: str):
|
|
| 250 |
agent_output = ""
|
| 251 |
|
| 252 |
# Stream from the agent
|
| 253 |
-
for agent_result, log_result in run_agent_stream(user_input):
|
| 254 |
if log_result:
|
| 255 |
log_buffer = log_result
|
| 256 |
if agent_result:
|
|
@@ -274,6 +302,23 @@ with gr.Blocks(css=custom_css, title="DeepDraft - Hardware Engineering Assistant
|
|
| 274 |
</div>
|
| 275 |
""")
|
| 276 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 277 |
# Main input section
|
| 278 |
with gr.Row():
|
| 279 |
with gr.Column(scale=3):
|
|
@@ -331,7 +376,7 @@ with gr.Blocks(css=custom_css, title="DeepDraft - Hardware Engineering Assistant
|
|
| 331 |
)
|
| 332 |
|
| 333 |
# Event handlers
|
| 334 |
-
def on_send_click(user_input):
|
| 335 |
if not user_input.strip():
|
| 336 |
return "", "", gr.HTML(visible=False)
|
| 337 |
|
|
@@ -351,11 +396,11 @@ with gr.Blocks(css=custom_css, title="DeepDraft - Hardware Engineering Assistant
|
|
| 351 |
# Connect the button click
|
| 352 |
send_button.click(
|
| 353 |
fn=on_send_click,
|
| 354 |
-
inputs=[user_input],
|
| 355 |
outputs=[agent_output, log_output, processing_indicator]
|
| 356 |
).then(
|
| 357 |
fn=run_agent_with_ui,
|
| 358 |
-
inputs=[user_input],
|
| 359 |
outputs=[agent_output, log_output],
|
| 360 |
concurrency_limit=1
|
| 361 |
).then(
|
|
|
|
| 85 |
}
|
| 86 |
|
| 87 |
.spinner {
|
| 88 |
+
border: 0.1875rem solid #f3f3f3;
|
| 89 |
+
border-top: 0.1875rem solid #3498db;
|
| 90 |
border-radius: 50%;
|
| 91 |
+
width: 1.25rem;
|
| 92 |
+
height: 1.25rem;
|
| 93 |
animation: spin 1s linear infinite;
|
| 94 |
margin-right: 0.5rem;
|
| 95 |
}
|
|
|
|
| 112 |
color: white !important;
|
| 113 |
border: none !important;
|
| 114 |
padding: 0.5rem 1.5rem !important;
|
| 115 |
+
border-radius: 0.5rem !important;
|
| 116 |
font-weight: 600 !important;
|
| 117 |
font-size: 0.95rem !important;
|
| 118 |
transition: all 0.3s ease !important;
|
| 119 |
+
box-shadow: 0 0.125rem 0.5rem rgba(0,123,255,0.3) !important;
|
| 120 |
+
min-width: 7.5rem !important;
|
| 121 |
+
max-width: 12.5rem !important;
|
| 122 |
}
|
| 123 |
|
| 124 |
.send-button:hover {
|
| 125 |
+
transform: translateY(-0.0625rem) !important;
|
| 126 |
+
box-shadow: 0 0.25rem 0.75rem rgba(0,123,255,0.4) !important;
|
| 127 |
}
|
| 128 |
|
| 129 |
.send-button:disabled {
|
|
|
|
| 138 |
line-height: 1.4;
|
| 139 |
color: var(--body-text-color);
|
| 140 |
background: var(--background-fill-secondary);
|
| 141 |
+
border: 0.0625rem solid var(--border-color-primary);
|
| 142 |
+
border-radius: 0.3125rem;
|
| 143 |
padding: 1rem;
|
| 144 |
+
max-height: 18.75rem;
|
| 145 |
overflow-y: auto;
|
| 146 |
}
|
| 147 |
|
|
|
|
| 213 |
.dark .tool-description {
|
| 214 |
color: var(--body-text-color);
|
| 215 |
}
|
| 216 |
+
|
| 217 |
+
.model-selector-compact {
|
| 218 |
+
background: transparent;
|
| 219 |
+
border: none;
|
| 220 |
+
padding: 0;
|
| 221 |
+
margin-bottom: 0.5rem;
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
.model-selector-compact .gr-dropdown {
|
| 225 |
+
background: var(--background-fill-primary);
|
| 226 |
+
color: var(--body-text-color);
|
| 227 |
+
border: 0.0625rem solid var(--border-color-primary);
|
| 228 |
+
border-radius: 0.375rem;
|
| 229 |
+
padding: 0.25rem 0.5rem;
|
| 230 |
+
font-size: 0.9rem;
|
| 231 |
+
max-width: 12.5rem !important;
|
| 232 |
+
}
|
| 233 |
+
|
| 234 |
+
.model-selector-compact .gr-dropdown:hover {
|
| 235 |
+
background: var(--background-fill-secondary);
|
| 236 |
+
border-color: var(--border-color-accent);
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
.model-selector-compact .gr-dropdown .gr-dropdown-label {
|
| 240 |
+
font-size: 0.85rem;
|
| 241 |
+
font-weight: 500;
|
| 242 |
+
margin-bottom: 0.25rem;
|
| 243 |
+
}
|
| 244 |
"""
|
| 245 |
|
| 246 |
def format_log_entry(log_text):
|
|
|
|
| 268 |
|
| 269 |
return "".join(formatted_lines)
|
| 270 |
|
| 271 |
+
def run_agent_with_ui(user_input: str, model_id: str):
|
| 272 |
"""Enhanced agent runner with better UI feedback"""
|
| 273 |
if not user_input.strip():
|
| 274 |
return "", ""
|
|
|
|
| 278 |
agent_output = ""
|
| 279 |
|
| 280 |
# Stream from the agent
|
| 281 |
+
for agent_result, log_result in run_agent_stream(user_input, model_id):
|
| 282 |
if log_result:
|
| 283 |
log_buffer = log_result
|
| 284 |
if agent_result:
|
|
|
|
| 302 |
</div>
|
| 303 |
""")
|
| 304 |
|
| 305 |
+
# Model selection (compact)
|
| 306 |
+
with gr.Row():
|
| 307 |
+
with gr.Column(scale=1):
|
| 308 |
+
model_selector = gr.Dropdown(
|
| 309 |
+
choices=[
|
| 310 |
+
("🤖 Mistral Medium", "mistral/mistral-medium-latest"),
|
| 311 |
+
("🧠 DeepSeek Reasoner", "deepseek/deepseek-reasoner"),
|
| 312 |
+
("🚀 DeepSeek Chat", "deepseek/deepseek-chat"),
|
| 313 |
+
("⚡ Mistral Small", "mistral/mistral-small-latest"),
|
| 314 |
+
],
|
| 315 |
+
value="mistral/mistral-medium-latest",
|
| 316 |
+
label="🤖 AI Model",
|
| 317 |
+
info="Choose the AI model for analysis",
|
| 318 |
+
elem_classes=["model-selector-compact"],
|
| 319 |
+
scale=1
|
| 320 |
+
)
|
| 321 |
+
|
| 322 |
# Main input section
|
| 323 |
with gr.Row():
|
| 324 |
with gr.Column(scale=3):
|
|
|
|
| 376 |
)
|
| 377 |
|
| 378 |
# Event handlers
|
| 379 |
+
def on_send_click(user_input, model_id):
|
| 380 |
if not user_input.strip():
|
| 381 |
return "", "", gr.HTML(visible=False)
|
| 382 |
|
|
|
|
| 396 |
# Connect the button click
|
| 397 |
send_button.click(
|
| 398 |
fn=on_send_click,
|
| 399 |
+
inputs=[user_input, model_selector],
|
| 400 |
outputs=[agent_output, log_output, processing_indicator]
|
| 401 |
).then(
|
| 402 |
fn=run_agent_with_ui,
|
| 403 |
+
inputs=[user_input, model_selector],
|
| 404 |
outputs=[agent_output, log_output],
|
| 405 |
concurrency_limit=1
|
| 406 |
).then(
|
src/deepengineer/backend/gradio_tools.py
CHANGED
|
@@ -27,7 +27,7 @@ def parse_markdown_images(markdown_text: str, image_dir: Path) -> str:
|
|
| 27 |
return re.sub(image_pattern, replace_image_path, markdown_text)
|
| 28 |
|
| 29 |
|
| 30 |
-
def run_agent_stream(user_input: str):
|
| 31 |
"""
|
| 32 |
Generator wired to Gradio:
|
| 33 |
– starts the agent in a background thread
|
|
@@ -48,7 +48,7 @@ def run_agent_stream(user_input: str):
|
|
| 48 |
|
| 49 |
def _worker():
|
| 50 |
answer_container["text"], answer_container["image_dir"] = main_search(
|
| 51 |
-
user_input, log_queue
|
| 52 |
)
|
| 53 |
done.set()
|
| 54 |
|
|
|
|
| 27 |
return re.sub(image_pattern, replace_image_path, markdown_text)
|
| 28 |
|
| 29 |
|
| 30 |
+
def run_agent_stream(user_input: str, model_id: str = "mistral/mistral-medium-latest"):
|
| 31 |
"""
|
| 32 |
Generator wired to Gradio:
|
| 33 |
– starts the agent in a background thread
|
|
|
|
| 48 |
|
| 49 |
def _worker():
|
| 50 |
answer_container["text"], answer_container["image_dir"] = main_search(
|
| 51 |
+
user_input, log_queue, model_id
|
| 52 |
)
|
| 53 |
done.set()
|
| 54 |
|
src/deepengineer/deepsearch/main_agent.py
CHANGED
|
@@ -77,7 +77,8 @@ def create_main_search_agent(
|
|
| 77 |
return search_agent
|
| 78 |
|
| 79 |
|
| 80 |
-
def main_search(task: str, log_queue: queue.Queue | None = None) -> tuple[str, Path]:
|
|
|
|
| 81 |
output_image_path = create_output_image_path()
|
| 82 |
MAIN_PROMPT = """
|
| 83 |
You are DeepDraft, an advanced research and analysis agent specialized in deep technical research, data visualization, and comprehensive information synthesis. You have access to powerful tools for web search, document analysis, and data visualization.
|
|
@@ -109,7 +110,7 @@ Run verification steps if that's needed, you must make sure you find the correct
|
|
| 109 |
{task}
|
| 110 |
"""
|
| 111 |
agent = create_main_search_agent(
|
| 112 |
-
model_id=
|
| 113 |
log_queue=log_queue,
|
| 114 |
output_image_path=output_image_path,
|
| 115 |
)
|
|
|
|
| 77 |
return search_agent
|
| 78 |
|
| 79 |
|
| 80 |
+
def main_search(task: str, log_queue: queue.Queue | None = None, model_id: str = "mistral/mistral-medium-latest") -> tuple[str, Path]:
|
| 81 |
+
print(f"Using model: {model_id}")
|
| 82 |
output_image_path = create_output_image_path()
|
| 83 |
MAIN_PROMPT = """
|
| 84 |
You are DeepDraft, an advanced research and analysis agent specialized in deep technical research, data visualization, and comprehensive information synthesis. You have access to powerful tools for web search, document analysis, and data visualization.
|
|
|
|
| 110 |
{task}
|
| 111 |
"""
|
| 112 |
agent = create_main_search_agent(
|
| 113 |
+
model_id=model_id,
|
| 114 |
log_queue=log_queue,
|
| 115 |
output_image_path=output_image_path,
|
| 116 |
)
|