Spaces:
Sleeping
Sleeping
Update v1.txt
Browse files
v1.txt
CHANGED
@@ -33,18 +33,18 @@ class ReasoningOrchestra:
|
|
33 |
return f"β API key validation failed: {str(e)}"
|
34 |
|
35 |
def format_text_to_html(self, text: str) -> str:
|
36 |
-
"""Convert text to HTML with proper formatting"""
|
37 |
if not text or text.strip() == "" or text == "No response generated":
|
38 |
-
return "<p style='color: #666; font-style: italic;'>No content was generated. This might be due to API limitations or model availability issues.</p>"
|
39 |
|
40 |
# Escape HTML characters first
|
41 |
text = html.escape(text)
|
42 |
|
43 |
-
# Convert markdown-style formatting to HTML
|
44 |
# Headers
|
45 |
-
text = re.sub(r'^### (.*$)', r'<h3>\1</h3>', text, flags=re.MULTILINE)
|
46 |
-
text = re.sub(r'^## (.*$)', r'<h2>\1</h2>', text, flags=re.MULTILINE)
|
47 |
-
text = re.sub(r'^# (.*$)', r'<h1>\1</h1>', text, flags=re.MULTILINE)
|
48 |
|
49 |
# Bold text
|
50 |
text = re.sub(r'\*\*(.*?)\*\*', r'<strong>\1</strong>', text)
|
@@ -53,8 +53,8 @@ class ReasoningOrchestra:
|
|
53 |
text = re.sub(r'\*(.*?)\*', r'<em>\1</em>', text)
|
54 |
|
55 |
# Code blocks
|
56 |
-
text = re.sub(r'```(.*?)```', r'<pre><code>\1</code></pre>', text, flags=re.DOTALL)
|
57 |
-
text = re.sub(r'`(.*?)`', r'<code>\1</code>', text)
|
58 |
|
59 |
# Lists
|
60 |
lines = text.split('\n')
|
@@ -65,12 +65,12 @@ class ReasoningOrchestra:
|
|
65 |
stripped = line.strip()
|
66 |
if stripped.startswith('- ') or stripped.startswith('* '):
|
67 |
if not in_list:
|
68 |
-
formatted_lines.append('<ul>')
|
69 |
in_list = True
|
70 |
formatted_lines.append(f'<li>{stripped[2:]}</li>')
|
71 |
elif stripped.startswith(('1. ', '2. ', '3. ', '4. ', '5. ', '6. ', '7. ', '8. ', '9. ')):
|
72 |
if not in_list:
|
73 |
-
formatted_lines.append('<ol>')
|
74 |
in_list = True
|
75 |
formatted_lines.append(f'<li>{stripped[3:]}</li>')
|
76 |
else:
|
@@ -78,7 +78,7 @@ class ReasoningOrchestra:
|
|
78 |
formatted_lines.append('</ul>' if any('<li>' in line for line in formatted_lines[-5:]) else '</ol>')
|
79 |
in_list = False
|
80 |
if stripped:
|
81 |
-
formatted_lines.append(f'<p>{line}</p>')
|
82 |
else:
|
83 |
formatted_lines.append('<br>')
|
84 |
|
@@ -178,7 +178,6 @@ Please conduct a thorough investigation including:
|
|
178 |
Be extremely thorough and leave no stone unturned. Provide detailed evidence and reasoning for your conclusions."""
|
179 |
|
180 |
try:
|
181 |
-
# Try with different parameters for QwQ model
|
182 |
completion = self.client.chat.completions.create(
|
183 |
model="qwen-qwq-32b",
|
184 |
messages=[{"role": "user", "content": prompt}],
|
@@ -189,7 +188,6 @@ Be extremely thorough and leave no stone unturned. Provide detailed evidence and
|
|
189 |
|
190 |
response_content = completion.choices[0].message.content
|
191 |
if not response_content or response_content.strip() == "":
|
192 |
-
# Fallback: try with a simpler prompt
|
193 |
fallback_prompt = f"Analyze this problem in detail: {problem}"
|
194 |
fallback_completion = self.client.chat.completions.create(
|
195 |
model="qwen-qwq-32b",
|
@@ -210,7 +208,6 @@ Be extremely thorough and leave no stone unturned. Provide detailed evidence and
|
|
210 |
"tokens_used": getattr(completion.usage, 'total_tokens', 'N/A') if hasattr(completion, 'usage') and completion.usage else "N/A"
|
211 |
}
|
212 |
except Exception as e:
|
213 |
-
# If QwQ fails, provide a helpful error message
|
214 |
error_msg = f"Detail Detective error: {str(e)}"
|
215 |
if "model" in str(e).lower() or "not found" in str(e).lower():
|
216 |
error_msg += "\n\nNote: The QwQ model may not be available in your region or may have usage restrictions. You can still use the other models in the orchestra."
|
@@ -221,7 +218,6 @@ Be extremely thorough and leave no stone unturned. Provide detailed evidence and
|
|
221 |
if not self.is_api_key_set:
|
222 |
return "API key not set"
|
223 |
|
224 |
-
# Extract reasoning content safely with better error handling
|
225 |
def extract_reasoning(result: Dict, model_name: str) -> str:
|
226 |
if result.get('error'):
|
227 |
return f"**{model_name} encountered an issue:** {result['error']}"
|
@@ -279,15 +275,15 @@ def validate_api_key(api_key: str) -> str:
|
|
279 |
def run_single_model(problem: str, model_choice: str, context: str = "") -> str:
|
280 |
"""Run a single model analysis"""
|
281 |
if not orchestra.is_api_key_set:
|
282 |
-
return """<div style="color: red; padding: 20px; border: 2px solid red; border-radius: 10px; background-color: #ffe6e6;">
|
283 |
-
<h3>β API Key Required</h3>
|
284 |
-
<p>Please set your Groq API key first in the API Configuration section above.</p>
|
285 |
</div>"""
|
286 |
|
287 |
if not problem.strip():
|
288 |
-
return """<div style="color: orange; padding: 20px; border: 2px solid orange; border-radius: 10px; background-color: #fff3e6;">
|
289 |
-
<h3>β οΈ Problem Required</h3>
|
290 |
-
<p>Please enter a problem to analyze.</p>
|
291 |
</div>"""
|
292 |
|
293 |
start_time = time.time()
|
@@ -299,17 +295,17 @@ def run_single_model(problem: str, model_choice: str, context: str = "") -> str:
|
|
299 |
elif model_choice == "Detail Detective (QwQ 32B)":
|
300 |
result = orchestra.detail_detective_analyze(problem, context)
|
301 |
else:
|
302 |
-
return """<div style="color: red; padding: 20px; border: 2px solid red; border-radius: 10px; background-color: #ffe6e6;">
|
303 |
-
<h3>β Invalid Model Selection</h3>
|
304 |
-
<p>Please select a valid model from the dropdown.</p>
|
305 |
</div>"""
|
306 |
|
307 |
elapsed_time = time.time() - start_time
|
308 |
|
309 |
if "error" in result:
|
310 |
-
return f"""<div style="color: red; padding: 20px; border: 2px solid red; border-radius: 10px; background-color: #ffe6e6;">
|
311 |
-
<h3>β Error</h3>
|
312 |
-
<p>{result['error']}</p>
|
313 |
</div>"""
|
314 |
|
315 |
# Format the response as HTML
|
@@ -318,11 +314,11 @@ def run_single_model(problem: str, model_choice: str, context: str = "") -> str:
|
|
318 |
formatted_output = f"""
|
319 |
<div style="border: 2px solid #28a745; border-radius: 15px; padding: 25px; margin: 15px 0; background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);">
|
320 |
<div style="display: flex; align-items: center; margin-bottom: 20px; padding-bottom: 15px; border-bottom: 2px solid #28a745;">
|
321 |
-
<h2 style="margin: 0; color: #28a745;">{result['role']}</h2>
|
322 |
</div>
|
323 |
|
324 |
<div style="background-color: white; padding: 15px; border-radius: 10px; margin-bottom: 20px;">
|
325 |
-
<div style="display: flex; gap: 20px; font-size:
|
326 |
<span><strong>Model:</strong> {result['model']}</span>
|
327 |
<span><strong>Analysis Time:</strong> {elapsed_time:.2f} seconds</span>
|
328 |
<span><strong>Timestamp:</strong> {result['timestamp']}</span>
|
@@ -330,7 +326,7 @@ def run_single_model(problem: str, model_choice: str, context: str = "") -> str:
|
|
330 |
</div>
|
331 |
</div>
|
332 |
|
333 |
-
<div style="background-color: white; padding: 20px; border-radius: 10px; line-height: 1.6;">
|
334 |
{reasoning_html}
|
335 |
</div>
|
336 |
</div>
|
@@ -341,16 +337,16 @@ def run_single_model(problem: str, model_choice: str, context: str = "") -> str:
|
|
341 |
def run_full_orchestra(problem: str, context: str = "") -> Tuple[str, str, str, str]:
|
342 |
"""Run the full collaborative reasoning orchestra"""
|
343 |
if not orchestra.is_api_key_set:
|
344 |
-
error_msg = """<div style="color: red; padding: 20px; border: 2px solid red; border-radius: 10px; background-color: #ffe6e6;">
|
345 |
-
<h3>β API Key Required</h3>
|
346 |
-
<p>Please set your Groq API key first in the API Configuration section above.</p>
|
347 |
</div>"""
|
348 |
return error_msg, error_msg, error_msg, error_msg
|
349 |
|
350 |
if not problem.strip():
|
351 |
-
error_msg = """<div style="color: orange; padding: 20px; border: 2px solid orange; border-radius: 10px; background-color: #fff3e6;">
|
352 |
-
<h3>β οΈ Problem Required</h3>
|
353 |
-
<p>Please enter a problem to analyze.</p>
|
354 |
</div>"""
|
355 |
return error_msg, error_msg, error_msg, error_msg
|
356 |
|
@@ -368,10 +364,10 @@ def run_full_orchestra(problem: str, context: str = "") -> Tuple[str, str, str,
|
|
368 |
|
369 |
def format_result_html(result: Dict, color: str, icon: str) -> str:
|
370 |
if "error" in result:
|
371 |
-
return f"""<div style="color: red; padding: 20px; border: 2px solid red; border-radius: 10px; background-color: #ffe6e6;">
|
372 |
-
<h3>β Model Error</h3>
|
373 |
-
<p>{result['error']}</p>
|
374 |
-
<p style="font-size:
|
375 |
</div>"""
|
376 |
|
377 |
reasoning_html = orchestra.format_text_to_html(result['reasoning'])
|
@@ -380,17 +376,17 @@ def run_full_orchestra(problem: str, context: str = "") -> Tuple[str, str, str,
|
|
380 |
<div style="border: 2px solid {color}; border-radius: 15px; padding: 25px; margin: 15px 0; background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);">
|
381 |
<div style="display: flex; align-items: center; margin-bottom: 20px; padding-bottom: 15px; border-bottom: 2px solid {color};">
|
382 |
<span style="font-size: 24px; margin-right: 10px;">{icon}</span>
|
383 |
-
<h2 style="margin: 0; color: {color};">{result['model']}</h2>
|
384 |
</div>
|
385 |
|
386 |
<div style="background-color: white; padding: 15px; border-radius: 10px; margin-bottom: 20px;">
|
387 |
-
<div style="display: flex; gap: 20px; font-size:
|
388 |
<span><strong>Timestamp:</strong> {result['timestamp']}</span>
|
389 |
<span><strong>Tokens:</strong> {result['tokens_used']}</span>
|
390 |
</div>
|
391 |
</div>
|
392 |
|
393 |
-
<div style="background-color: white; padding: 20px; border-radius: 10px; line-height: 1.6;">
|
394 |
{reasoning_html}
|
395 |
</div>
|
396 |
</div>
|
@@ -405,10 +401,10 @@ def run_full_orchestra(problem: str, context: str = "") -> Tuple[str, str, str,
|
|
405 |
<div style="border: 2px solid #dc3545; border-radius: 15px; padding: 25px; margin: 15px 0; background: linear-gradient(135deg, #fff5f5 0%, #fee);">
|
406 |
<div style="display: flex; align-items: center; margin-bottom: 20px; padding-bottom: 15px; border-bottom: 2px solid #dc3545;">
|
407 |
<span style="font-size: 24px; margin-right: 10px;">πΌ</span>
|
408 |
-
<h2 style="margin: 0; color: #dc3545;">Orchestra Conductor - Final Synthesis (Llama 3.3 70B Versatile)</h2>
|
409 |
</div>
|
410 |
|
411 |
-
<div style="background-color: white; padding: 20px; border-radius: 10px; line-height: 1.6;">
|
412 |
{synthesis_html}
|
413 |
</div>
|
414 |
</div>
|
@@ -416,11 +412,12 @@ def run_full_orchestra(problem: str, context: str = "") -> Tuple[str, str, str,
|
|
416 |
|
417 |
return deep_output, strategic_output, detective_output, synthesis_output
|
418 |
|
419 |
-
# Custom CSS for better styling
|
420 |
custom_css = """
|
421 |
.gradio-container {
|
422 |
max-width: 1400px !important;
|
423 |
margin: 0 auto !important;
|
|
|
424 |
}
|
425 |
.api-key-section {
|
426 |
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
@@ -440,6 +437,7 @@ custom_css = """
|
|
440 |
padding: 20px;
|
441 |
border-radius: 15px;
|
442 |
margin-bottom: 20px;
|
|
|
443 |
}
|
444 |
.status-box {
|
445 |
background-color: #f8f9fa;
|
@@ -447,6 +445,7 @@ custom_css = """
|
|
447 |
padding: 15px;
|
448 |
margin: 10px 0;
|
449 |
border-radius: 5px;
|
|
|
450 |
}
|
451 |
/* Custom styling for HTML outputs */
|
452 |
.html-content {
|
@@ -456,6 +455,27 @@ custom_css = """
|
|
456 |
border-radius: 8px;
|
457 |
padding: 10px;
|
458 |
background-color: #fafafa;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
459 |
}
|
460 |
"""
|
461 |
|
@@ -464,29 +484,31 @@ with gr.Blocks(css=custom_css, title="Reasoning Orchestra") as app:
|
|
464 |
# Header
|
465 |
gr.HTML("""
|
466 |
<div class="orchestra-header">
|
467 |
-
<h1>πΌ The Collaborative Reasoning Orchestra</h1>
|
468 |
-
<p><em>Where AI models collaborate like musicians in an orchestra to solve complex problems</em></p>
|
469 |
-
<p><strong>Now with Llama 3.3 70B Versatile as Orchestra Conductor & Enhanced HTML-Formatted Responses!</strong></p>
|
470 |
</div>
|
471 |
""")
|
472 |
|
473 |
# API Key Section
|
474 |
with gr.Group():
|
475 |
-
gr.HTML('<div class="api-key-section"><h3 style="color: white; margin-top: 0;">π API Configuration</h3></div>')
|
476 |
with gr.Row():
|
477 |
api_key_input = gr.Textbox(
|
478 |
label="Enter your Groq API Key",
|
479 |
type="password",
|
480 |
placeholder="gsk_...",
|
481 |
-
info="Get your free API key from https://console.groq.com/keys"
|
|
|
482 |
)
|
483 |
api_status = gr.Textbox(
|
484 |
label="API Status",
|
485 |
interactive=False,
|
486 |
-
placeholder="Enter API key to validate..."
|
|
|
487 |
)
|
488 |
|
489 |
-
validate_btn = gr.Button("π Validate API Key", variant="primary")
|
490 |
validate_btn.click(
|
491 |
fn=validate_api_key,
|
492 |
inputs=[api_key_input],
|
@@ -505,12 +527,14 @@ with gr.Blocks(css=custom_css, title="Reasoning Orchestra") as app:
|
|
505 |
single_problem = gr.Textbox(
|
506 |
label="Problem Statement",
|
507 |
placeholder="Enter the problem you want to analyze...",
|
508 |
-
lines=4
|
|
|
509 |
)
|
510 |
single_context = gr.Textbox(
|
511 |
label="Additional Context (Optional)",
|
512 |
placeholder="Any additional context or constraints...",
|
513 |
-
lines=2
|
|
|
514 |
)
|
515 |
model_choice = gr.Dropdown(
|
516 |
label="Choose Model",
|
@@ -519,12 +543,13 @@ with gr.Blocks(css=custom_css, title="Reasoning Orchestra") as app:
|
|
519 |
"Quick Strategist (Qwen3 32B)",
|
520 |
"Detail Detective (QwQ 32B)"
|
521 |
],
|
522 |
-
value="Deep Thinker (DeepSeek R1)"
|
|
|
523 |
)
|
524 |
-
single_analyze_btn = gr.Button("π Analyze with HTML Output", variant="primary", size="lg")
|
525 |
|
526 |
with gr.Column(scale=2):
|
527 |
-
single_output = gr.HTML(label="Analysis Result", elem_classes=["html-content"])
|
528 |
|
529 |
single_analyze_btn.click(
|
530 |
fn=run_single_model,
|
@@ -542,21 +567,23 @@ with gr.Blocks(css=custom_css, title="Reasoning Orchestra") as app:
|
|
542 |
orchestra_problem = gr.Textbox(
|
543 |
label="Problem Statement",
|
544 |
placeholder="Enter a complex problem that benefits from multiple reasoning perspectives...",
|
545 |
-
lines=6
|
|
|
546 |
)
|
547 |
orchestra_context = gr.Textbox(
|
548 |
label="Additional Context (Optional)",
|
549 |
placeholder="Background information, constraints, or specific requirements...",
|
550 |
-
lines=3
|
|
|
551 |
)
|
552 |
-
orchestra_analyze_btn = gr.Button("πΌ Start Orchestra Analysis", variant="primary", size="lg")
|
553 |
|
554 |
# Orchestra Results
|
555 |
with gr.Column():
|
556 |
-
deep_output = gr.HTML(label="π Deep Thinker Analysis", elem_classes=["html-content"])
|
557 |
-
strategic_output = gr.HTML(label="π Quick Strategist Analysis", elem_classes=["html-content"])
|
558 |
-
detective_output = gr.HTML(label="π Detail Detective Analysis", elem_classes=["html-content"])
|
559 |
-
synthesis_output = gr.HTML(label="πΌ Final Orchestrated Solution (Llama 3.3 70B)", elem_classes=["html-content"])
|
560 |
|
561 |
orchestra_analyze_btn.click(
|
562 |
fn=run_full_orchestra,
|
@@ -593,30 +620,30 @@ with gr.Blocks(css=custom_css, title="Reasoning Orchestra") as app:
|
|
593 |
|
594 |
# Footer
|
595 |
gr.HTML("""
|
596 |
-
<div style="text-align: center; margin-top: 30px; padding: 20px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); border-radius: 15px; color: white;">
|
597 |
-
<h3>πΌ How the Orchestra Works</h3>
|
598 |
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 20px; margin: 20px 0;">
|
599 |
<div style="background: rgba(255,255,255,0.1); padding: 15px; border-radius: 10px;">
|
600 |
-
<h4>π Deep Thinker (DeepSeek R1)</h4>
|
601 |
-
<p>Provides thorough philosophical and theoretical analysis with comprehensive reasoning chains</p>
|
602 |
</div>
|
603 |
<div style="background: rgba(255,255,255,0.1); padding: 15px; border-radius: 10px;">
|
604 |
-
<h4>π Quick Strategist (Qwen3 32B)</h4>
|
605 |
-
<p>Delivers practical strategies, action plans, and rapid decision-making frameworks</p>
|
606 |
</div>
|
607 |
<div style="background: rgba(255,255,255,0.1); padding: 15px; border-radius: 10px;">
|
608 |
-
<h4>π Detail Detective (QwQ 32B)</h4>
|
609 |
-
<p>Conducts comprehensive investigation, fact-checking, and finds hidden connections</p>
|
610 |
</div>
|
611 |
<div style="background: rgba(255,255,255,0.1); padding: 15px; border-radius: 10px;">
|
612 |
-
<h4>πΌ Orchestra Conductor</h4>
|
613 |
-
<p>Synthesizes all perspectives into unified, comprehensive solutions</p>
|
614 |
</div>
|
615 |
</div>
|
616 |
-
<p style="margin-top: 20px;"><em>Built with β€οΈ using Groq's lightning-fast inference, Gradio, and beautiful HTML formatting</em></p>
|
617 |
</div>
|
618 |
""")
|
619 |
|
620 |
# Launch the app
|
621 |
if __name__ == "__main__":
|
622 |
-
app.launch(share=False)
|
|
|
33 |
return f"β API key validation failed: {str(e)}"
|
34 |
|
35 |
def format_text_to_html(self, text: str) -> str:
|
36 |
+
"""Convert text to HTML with proper formatting and consistent font size"""
|
37 |
if not text or text.strip() == "" or text == "No response generated":
|
38 |
+
return "<p style='color: #666; font-style: italic; font-size: 16px;'>No content was generated. This might be due to API limitations or model availability issues.</p>"
|
39 |
|
40 |
# Escape HTML characters first
|
41 |
text = html.escape(text)
|
42 |
|
43 |
+
# Convert markdown-style formatting to HTML with consistent font sizes
|
44 |
# Headers
|
45 |
+
text = re.sub(r'^### (.*$)', r'<h3 style="font-size: 18px;">\1</h3>', text, flags=re.MULTILINE)
|
46 |
+
text = re.sub(r'^## (.*$)', r'<h2 style="font-size: 20px;">\1</h2>', text, flags=re.MULTILINE)
|
47 |
+
text = re.sub(r'^# (.*$)', r'<h1 style="font-size: 22px;">\1</h1>', text, flags=re.MULTILINE)
|
48 |
|
49 |
# Bold text
|
50 |
text = re.sub(r'\*\*(.*?)\*\*', r'<strong>\1</strong>', text)
|
|
|
53 |
text = re.sub(r'\*(.*?)\*', r'<em>\1</em>', text)
|
54 |
|
55 |
# Code blocks
|
56 |
+
text = re.sub(r'```(.*?)```', r'<pre style="font-size: 15px; background: #f5f5f5; padding: 10px; border-radius: 5px;"><code>\1</code></pre>', text, flags=re.DOTALL)
|
57 |
+
text = re.sub(r'`(.*?)`', r'<code style="font-size: 15px; background: #f5f5f5; padding: 2px 4px; border-radius: 3px;">\1</code>', text)
|
58 |
|
59 |
# Lists
|
60 |
lines = text.split('\n')
|
|
|
65 |
stripped = line.strip()
|
66 |
if stripped.startswith('- ') or stripped.startswith('* '):
|
67 |
if not in_list:
|
68 |
+
formatted_lines.append('<ul style="font-size: 16px;">')
|
69 |
in_list = True
|
70 |
formatted_lines.append(f'<li>{stripped[2:]}</li>')
|
71 |
elif stripped.startswith(('1. ', '2. ', '3. ', '4. ', '5. ', '6. ', '7. ', '8. ', '9. ')):
|
72 |
if not in_list:
|
73 |
+
formatted_lines.append('<ol style="font-size: 16px;">')
|
74 |
in_list = True
|
75 |
formatted_lines.append(f'<li>{stripped[3:]}</li>')
|
76 |
else:
|
|
|
78 |
formatted_lines.append('</ul>' if any('<li>' in line for line in formatted_lines[-5:]) else '</ol>')
|
79 |
in_list = False
|
80 |
if stripped:
|
81 |
+
formatted_lines.append(f'<p style="font-size: 16px; margin: 8px 0;">{line}</p>')
|
82 |
else:
|
83 |
formatted_lines.append('<br>')
|
84 |
|
|
|
178 |
Be extremely thorough and leave no stone unturned. Provide detailed evidence and reasoning for your conclusions."""
|
179 |
|
180 |
try:
|
|
|
181 |
completion = self.client.chat.completions.create(
|
182 |
model="qwen-qwq-32b",
|
183 |
messages=[{"role": "user", "content": prompt}],
|
|
|
188 |
|
189 |
response_content = completion.choices[0].message.content
|
190 |
if not response_content or response_content.strip() == "":
|
|
|
191 |
fallback_prompt = f"Analyze this problem in detail: {problem}"
|
192 |
fallback_completion = self.client.chat.completions.create(
|
193 |
model="qwen-qwq-32b",
|
|
|
208 |
"tokens_used": getattr(completion.usage, 'total_tokens', 'N/A') if hasattr(completion, 'usage') and completion.usage else "N/A"
|
209 |
}
|
210 |
except Exception as e:
|
|
|
211 |
error_msg = f"Detail Detective error: {str(e)}"
|
212 |
if "model" in str(e).lower() or "not found" in str(e).lower():
|
213 |
error_msg += "\n\nNote: The QwQ model may not be available in your region or may have usage restrictions. You can still use the other models in the orchestra."
|
|
|
218 |
if not self.is_api_key_set:
|
219 |
return "API key not set"
|
220 |
|
|
|
221 |
def extract_reasoning(result: Dict, model_name: str) -> str:
|
222 |
if result.get('error'):
|
223 |
return f"**{model_name} encountered an issue:** {result['error']}"
|
|
|
275 |
def run_single_model(problem: str, model_choice: str, context: str = "") -> str:
|
276 |
"""Run a single model analysis"""
|
277 |
if not orchestra.is_api_key_set:
|
278 |
+
return """<div style="color: red; padding: 20px; border: 2px solid red; border-radius: 10px; background-color: #ffe6e6; font-size: 16px;">
|
279 |
+
<h3 style="font-size: 18px;">β API Key Required</h3>
|
280 |
+
<p style="font-size: 16px;">Please set your Groq API key first in the API Configuration section above.</p>
|
281 |
</div>"""
|
282 |
|
283 |
if not problem.strip():
|
284 |
+
return """<div style="color: orange; padding: 20px; border: 2px solid orange; border-radius: 10px; background-color: #fff3e6; font-size: 16px;">
|
285 |
+
<h3 style="font-size: 18px;">β οΈ Problem Required</h3>
|
286 |
+
<p style="font-size: 16px;">Please enter a problem to analyze.</p>
|
287 |
</div>"""
|
288 |
|
289 |
start_time = time.time()
|
|
|
295 |
elif model_choice == "Detail Detective (QwQ 32B)":
|
296 |
result = orchestra.detail_detective_analyze(problem, context)
|
297 |
else:
|
298 |
+
return """<div style="color: red; padding: 20px; border: 2px solid red; border-radius: 10px; background-color: #ffe6e6; font-size: 16px;">
|
299 |
+
<h3 style="font-size: 18px;">β Invalid Model Selection</h3>
|
300 |
+
<p style="font-size: 16px;">Please select a valid model from the dropdown.</p>
|
301 |
</div>"""
|
302 |
|
303 |
elapsed_time = time.time() - start_time
|
304 |
|
305 |
if "error" in result:
|
306 |
+
return f"""<div style="color: red; padding: 20px; border: 2px solid red; border-radius: 10px; background-color: #ffe6e6; font-size: 16px;">
|
307 |
+
<h3 style="font-size: 18px;">β Error</h3>
|
308 |
+
<p style="font-size: 16px;">{result['error']}</p>
|
309 |
</div>"""
|
310 |
|
311 |
# Format the response as HTML
|
|
|
314 |
formatted_output = f"""
|
315 |
<div style="border: 2px solid #28a745; border-radius: 15px; padding: 25px; margin: 15px 0; background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);">
|
316 |
<div style="display: flex; align-items: center; margin-bottom: 20px; padding-bottom: 15px; border-bottom: 2px solid #28a745;">
|
317 |
+
<h2 style="margin: 0; color: #28a745; font-size: 22px;">{result['role']}</h2>
|
318 |
</div>
|
319 |
|
320 |
<div style="background-color: white; padding: 15px; border-radius: 10px; margin-bottom: 20px;">
|
321 |
+
<div style="display: flex; gap: 20px; font-size: 16px; color: #666;">
|
322 |
<span><strong>Model:</strong> {result['model']}</span>
|
323 |
<span><strong>Analysis Time:</strong> {elapsed_time:.2f} seconds</span>
|
324 |
<span><strong>Timestamp:</strong> {result['timestamp']}</span>
|
|
|
326 |
</div>
|
327 |
</div>
|
328 |
|
329 |
+
<div style="background-color: white; padding: 20px; border-radius: 10px; line-height: 1.6; font-size: 16px;">
|
330 |
{reasoning_html}
|
331 |
</div>
|
332 |
</div>
|
|
|
337 |
def run_full_orchestra(problem: str, context: str = "") -> Tuple[str, str, str, str]:
|
338 |
"""Run the full collaborative reasoning orchestra"""
|
339 |
if not orchestra.is_api_key_set:
|
340 |
+
error_msg = """<div style="color: red; padding: 20px; border: 2px solid red; border-radius: 10px; background-color: #ffe6e6; font-size: 16px;">
|
341 |
+
<h3 style="font-size: 18px;">β API Key Required</h3>
|
342 |
+
<p style="font-size: 16px;">Please set your Groq API key first in the API Configuration section above.</p>
|
343 |
</div>"""
|
344 |
return error_msg, error_msg, error_msg, error_msg
|
345 |
|
346 |
if not problem.strip():
|
347 |
+
error_msg = """<div style="color: orange; padding: 20px; border: 2px solid orange; border-radius: 10px; background-color: #fff3e6; font-size: 16px;">
|
348 |
+
<h3 style="font-size: 18px;">β οΈ Problem Required</h3>
|
349 |
+
<p style="font-size: 16px;">Please enter a problem to analyze.</p>
|
350 |
</div>"""
|
351 |
return error_msg, error_msg, error_msg, error_msg
|
352 |
|
|
|
364 |
|
365 |
def format_result_html(result: Dict, color: str, icon: str) -> str:
|
366 |
if "error" in result:
|
367 |
+
return f"""<div style="color: red; padding: 20px; border: 2px solid red; border-radius: 10px; background-color: #ffe6e6; font-size: 16px;">
|
368 |
+
<h3 style="font-size: 18px;">β Model Error</h3>
|
369 |
+
<p style="font-size: 16px;">{result['error']}</p>
|
370 |
+
<p style="font-size: 14px; color: #666; margin-top: 10px;"><em>This model may have restrictions or temporary availability issues. The other models can still provide analysis.</em></p>
|
371 |
</div>"""
|
372 |
|
373 |
reasoning_html = orchestra.format_text_to_html(result['reasoning'])
|
|
|
376 |
<div style="border: 2px solid {color}; border-radius: 15px; padding: 25px; margin: 15px 0; background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);">
|
377 |
<div style="display: flex; align-items: center; margin-bottom: 20px; padding-bottom: 15px; border-bottom: 2px solid {color};">
|
378 |
<span style="font-size: 24px; margin-right: 10px;">{icon}</span>
|
379 |
+
<h2 style="margin: 0; color: {color}; font-size: 22px;">{result['model']}</h2>
|
380 |
</div>
|
381 |
|
382 |
<div style="background-color: white; padding: 15px; border-radius: 10px; margin-bottom: 20px;">
|
383 |
+
<div style="display: flex; gap: 20px; font-size: 16px; color: #666;">
|
384 |
<span><strong>Timestamp:</strong> {result['timestamp']}</span>
|
385 |
<span><strong>Tokens:</strong> {result['tokens_used']}</span>
|
386 |
</div>
|
387 |
</div>
|
388 |
|
389 |
+
<div style="background-color: white; padding: 20px; border-radius: 10px; line-height: 1.6; font-size: 16px;">
|
390 |
{reasoning_html}
|
391 |
</div>
|
392 |
</div>
|
|
|
401 |
<div style="border: 2px solid #dc3545; border-radius: 15px; padding: 25px; margin: 15px 0; background: linear-gradient(135deg, #fff5f5 0%, #fee);">
|
402 |
<div style="display: flex; align-items: center; margin-bottom: 20px; padding-bottom: 15px; border-bottom: 2px solid #dc3545;">
|
403 |
<span style="font-size: 24px; margin-right: 10px;">πΌ</span>
|
404 |
+
<h2 style="margin: 0; color: #dc3545; font-size: 22px;">Orchestra Conductor - Final Synthesis (Llama 3.3 70B Versatile)</h2>
|
405 |
</div>
|
406 |
|
407 |
+
<div style="background-color: white; padding: 20px; border-radius: 10px; line-height: 1.6; font-size: 16px;">
|
408 |
{synthesis_html}
|
409 |
</div>
|
410 |
</div>
|
|
|
412 |
|
413 |
return deep_output, strategic_output, detective_output, synthesis_output
|
414 |
|
415 |
+
# Custom CSS for better styling with consistent font sizes
|
416 |
custom_css = """
|
417 |
.gradio-container {
|
418 |
max-width: 1400px !important;
|
419 |
margin: 0 auto !important;
|
420 |
+
font-size: 16px !important;
|
421 |
}
|
422 |
.api-key-section {
|
423 |
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
|
437 |
padding: 20px;
|
438 |
border-radius: 15px;
|
439 |
margin-bottom: 20px;
|
440 |
+
font-size: 16px;
|
441 |
}
|
442 |
.status-box {
|
443 |
background-color: #f8f9fa;
|
|
|
445 |
padding: 15px;
|
446 |
margin: 10px 0;
|
447 |
border-radius: 5px;
|
448 |
+
font-size: 16px;
|
449 |
}
|
450 |
/* Custom styling for HTML outputs */
|
451 |
.html-content {
|
|
|
455 |
border-radius: 8px;
|
456 |
padding: 10px;
|
457 |
background-color: #fafafa;
|
458 |
+
font-size: 16px !important;
|
459 |
+
}
|
460 |
+
/* Ensure all text has consistent font size */
|
461 |
+
p, li, span, div, textarea, input, select, button {
|
462 |
+
font-size: 16px !important;
|
463 |
+
}
|
464 |
+
h1 {
|
465 |
+
font-size: 24px !important;
|
466 |
+
}
|
467 |
+
h2 {
|
468 |
+
font-size: 22px !important;
|
469 |
+
}
|
470 |
+
h3 {
|
471 |
+
font-size: 20px !important;
|
472 |
+
}
|
473 |
+
h4 {
|
474 |
+
font-size: 18px !important;
|
475 |
+
}
|
476 |
+
/* Make sure code blocks are readable */
|
477 |
+
pre, code {
|
478 |
+
font-size: 15px !important;
|
479 |
}
|
480 |
"""
|
481 |
|
|
|
484 |
# Header
|
485 |
gr.HTML("""
|
486 |
<div class="orchestra-header">
|
487 |
+
<h1 style="font-size: 28px;">πΌ The Collaborative Reasoning Orchestra</h1>
|
488 |
+
<p style="font-size: 18px;"><em>Where AI models collaborate like musicians in an orchestra to solve complex problems</em></p>
|
489 |
+
<p style="font-size: 18px;"><strong>Now with Llama 3.3 70B Versatile as Orchestra Conductor & Enhanced HTML-Formatted Responses!</strong></p>
|
490 |
</div>
|
491 |
""")
|
492 |
|
493 |
# API Key Section
|
494 |
with gr.Group():
|
495 |
+
gr.HTML('<div class="api-key-section"><h3 style="color: white; margin-top: 0; font-size: 20px;">π API Configuration</h3></div>')
|
496 |
with gr.Row():
|
497 |
api_key_input = gr.Textbox(
|
498 |
label="Enter your Groq API Key",
|
499 |
type="password",
|
500 |
placeholder="gsk_...",
|
501 |
+
info="Get your free API key from https://console.groq.com/keys",
|
502 |
+
elem_id="api_key_input"
|
503 |
)
|
504 |
api_status = gr.Textbox(
|
505 |
label="API Status",
|
506 |
interactive=False,
|
507 |
+
placeholder="Enter API key to validate...",
|
508 |
+
elem_id="api_status"
|
509 |
)
|
510 |
|
511 |
+
validate_btn = gr.Button("π Validate API Key", variant="primary", elem_id="validate_btn")
|
512 |
validate_btn.click(
|
513 |
fn=validate_api_key,
|
514 |
inputs=[api_key_input],
|
|
|
527 |
single_problem = gr.Textbox(
|
528 |
label="Problem Statement",
|
529 |
placeholder="Enter the problem you want to analyze...",
|
530 |
+
lines=4,
|
531 |
+
elem_id="single_problem"
|
532 |
)
|
533 |
single_context = gr.Textbox(
|
534 |
label="Additional Context (Optional)",
|
535 |
placeholder="Any additional context or constraints...",
|
536 |
+
lines=2,
|
537 |
+
elem_id="single_context"
|
538 |
)
|
539 |
model_choice = gr.Dropdown(
|
540 |
label="Choose Model",
|
|
|
543 |
"Quick Strategist (Qwen3 32B)",
|
544 |
"Detail Detective (QwQ 32B)"
|
545 |
],
|
546 |
+
value="Deep Thinker (DeepSeek R1)",
|
547 |
+
elem_id="model_choice"
|
548 |
)
|
549 |
+
single_analyze_btn = gr.Button("π Analyze with HTML Output", variant="primary", size="lg", elem_id="single_analyze_btn")
|
550 |
|
551 |
with gr.Column(scale=2):
|
552 |
+
single_output = gr.HTML(label="Analysis Result", elem_classes=["html-content"], elem_id="single_output")
|
553 |
|
554 |
single_analyze_btn.click(
|
555 |
fn=run_single_model,
|
|
|
567 |
orchestra_problem = gr.Textbox(
|
568 |
label="Problem Statement",
|
569 |
placeholder="Enter a complex problem that benefits from multiple reasoning perspectives...",
|
570 |
+
lines=6,
|
571 |
+
elem_id="orchestra_problem"
|
572 |
)
|
573 |
orchestra_context = gr.Textbox(
|
574 |
label="Additional Context (Optional)",
|
575 |
placeholder="Background information, constraints, or specific requirements...",
|
576 |
+
lines=3,
|
577 |
+
elem_id="orchestra_context"
|
578 |
)
|
579 |
+
orchestra_analyze_btn = gr.Button("πΌ Start Orchestra Analysis", variant="primary", size="lg", elem_id="orchestra_analyze_btn")
|
580 |
|
581 |
# Orchestra Results
|
582 |
with gr.Column():
|
583 |
+
deep_output = gr.HTML(label="π Deep Thinker Analysis", elem_classes=["html-content"], elem_id="deep_output")
|
584 |
+
strategic_output = gr.HTML(label="π Quick Strategist Analysis", elem_classes=["html-content"], elem_id="strategic_output")
|
585 |
+
detective_output = gr.HTML(label="π Detail Detective Analysis", elem_classes=["html-content"], elem_id="detective_output")
|
586 |
+
synthesis_output = gr.HTML(label="πΌ Final Orchestrated Solution (Llama 3.3 70B)", elem_classes=["html-content"], elem_id="synthesis_output")
|
587 |
|
588 |
orchestra_analyze_btn.click(
|
589 |
fn=run_full_orchestra,
|
|
|
620 |
|
621 |
# Footer
|
622 |
gr.HTML("""
|
623 |
+
<div style="text-align: center; margin-top: 30px; padding: 20px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); border-radius: 15px; color: white; font-size: 16px;">
|
624 |
+
<h3 style="font-size: 22px;">πΌ How the Orchestra Works</h3>
|
625 |
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 20px; margin: 20px 0;">
|
626 |
<div style="background: rgba(255,255,255,0.1); padding: 15px; border-radius: 10px;">
|
627 |
+
<h4 style="font-size: 18px;">π Deep Thinker (DeepSeek R1)</h4>
|
628 |
+
<p style="font-size: 16px;">Provides thorough philosophical and theoretical analysis with comprehensive reasoning chains</p>
|
629 |
</div>
|
630 |
<div style="background: rgba(255,255,255,0.1); padding: 15px; border-radius: 10px;">
|
631 |
+
<h4 style="font-size: 18px;">π Quick Strategist (Qwen3 32B)</h4>
|
632 |
+
<p style="font-size: 16px;">Delivers practical strategies, action plans, and rapid decision-making frameworks</p>
|
633 |
</div>
|
634 |
<div style="background: rgba(255,255,255,0.1); padding: 15px; border-radius: 10px;">
|
635 |
+
<h4 style="font-size: 18px;">π Detail Detective (QwQ 32B)</h4>
|
636 |
+
<p style="font-size: 16px;">Conducts comprehensive investigation, fact-checking, and finds hidden connections</p>
|
637 |
</div>
|
638 |
<div style="background: rgba(255,255,255,0.1); padding: 15px; border-radius: 10px;">
|
639 |
+
<h4 style="font-size: 18px;">πΌ Orchestra Conductor</h4>
|
640 |
+
<p style="font-size: 16px;">Synthesizes all perspectives into unified, comprehensive solutions</p>
|
641 |
</div>
|
642 |
</div>
|
643 |
+
<p style="margin-top: 20px; font-size: 16px;"><em>Built with β€οΈ using Groq's lightning-fast inference, Gradio, and beautiful HTML formatting</em></p>
|
644 |
</div>
|
645 |
""")
|
646 |
|
647 |
# Launch the app
|
648 |
if __name__ == "__main__":
|
649 |
+
app.launch(share=False)
|