Spaces:
Runtime error
Runtime error
Leonardo
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
import re
|
| 3 |
import shutil
|
|
@@ -253,10 +256,12 @@ def create_agent() -> CodeAgent:
|
|
| 253 |
RuntimeError: If agent creation fails.
|
| 254 |
"""
|
| 255 |
try:
|
|
|
|
|
|
|
| 256 |
# Initialize model
|
| 257 |
model = LiteLLMModel(
|
| 258 |
custom_role_conversions=CUSTOM_ROLE_CONVERSIONS,
|
| 259 |
-
model_id=
|
| 260 |
)
|
| 261 |
|
| 262 |
# Initialize tools
|
|
@@ -492,10 +497,10 @@ class GradioUI:
|
|
| 492 |
uploaded_files,
|
| 493 |
)
|
| 494 |
|
| 495 |
-
def detect_device(self, request: gr.Request):
|
| 496 |
"""Detect whether the user is on mobile or desktop device."""
|
| 497 |
if not request:
|
| 498 |
-
return "
|
| 499 |
|
| 500 |
is_mobile_header = request.headers.get("sec-ch-ua-mobile")
|
| 501 |
if is_mobile_header:
|
|
@@ -518,20 +523,58 @@ class GradioUI:
|
|
| 518 |
def launch(self, **kwargs):
|
| 519 |
"""Launch the Gradio UI with responsive layout."""
|
| 520 |
with gr.Blocks(theme="ocean", fill_height=True) as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 521 |
|
| 522 |
-
|
| 523 |
-
|
| 524 |
-
|
| 525 |
-
|
| 526 |
-
|
| 527 |
-
|
| 528 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 529 |
|
| 530 |
demo.queue(max_size=20).launch(debug=True, **kwargs)
|
| 531 |
|
| 532 |
def _create_desktop_layout(self):
|
| 533 |
"""Create the desktop layout with sidebar and enhanced styling."""
|
| 534 |
-
with gr.
|
| 535 |
with gr.Sidebar():
|
| 536 |
gr.Markdown(
|
| 537 |
"""# 🔍 OpenDeepResearch
|
|
@@ -623,7 +666,7 @@ class GradioUI:
|
|
| 623 |
|
| 624 |
def _create_mobile_layout(self):
|
| 625 |
"""Create the mobile layout (simpler without sidebar)."""
|
| 626 |
-
with gr.
|
| 627 |
gr.Markdown("""#OpenDeepResearch - free the AI agents!""")
|
| 628 |
session_state = gr.State({})
|
| 629 |
stored_messages = gr.State([])
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
# coding=utf-8
|
| 3 |
+
# Copyright 2024 The Footscray Coding Collective. All rights reserved.
|
| 4 |
import os
|
| 5 |
import re
|
| 6 |
import shutil
|
|
|
|
| 256 |
RuntimeError: If agent creation fails.
|
| 257 |
"""
|
| 258 |
try:
|
| 259 |
+
# Model Configuration
|
| 260 |
+
model_id = "openrouter/deepseek/deepseek-chat-v3-0324:free" # Define Model
|
| 261 |
# Initialize model
|
| 262 |
model = LiteLLMModel(
|
| 263 |
custom_role_conversions=CUSTOM_ROLE_CONVERSIONS,
|
| 264 |
+
model_id=model_id,
|
| 265 |
)
|
| 266 |
|
| 267 |
# Initialize tools
|
|
|
|
| 497 |
uploaded_files,
|
| 498 |
)
|
| 499 |
|
| 500 |
+
def detect_device(self, request: gr.Request) -> str:
|
| 501 |
"""Detect whether the user is on mobile or desktop device."""
|
| 502 |
if not request:
|
| 503 |
+
return "Desktop"
|
| 504 |
|
| 505 |
is_mobile_header = request.headers.get("sec-ch-ua-mobile")
|
| 506 |
if is_mobile_header:
|
|
|
|
| 523 |
def launch(self, **kwargs):
|
| 524 |
"""Launch the Gradio UI with responsive layout."""
|
| 525 |
with gr.Blocks(theme="ocean", fill_height=True) as demo:
|
| 526 |
+
# JavaScript-based layout
|
| 527 |
+
demo.load(
|
| 528 |
+
None, # No server-side function on load
|
| 529 |
+
[],
|
| 530 |
+
[],
|
| 531 |
+
_js="""
|
| 532 |
+
() => {
|
| 533 |
+
const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
|
| 534 |
+
if (isMobile) {
|
| 535 |
+
// Mobile-specific logic (e.g., hide/show certain elements)
|
| 536 |
+
document.body.classList.add('mobile-layout'); // Example: Add a CSS class
|
| 537 |
+
console.log('Mobile layout applied.');
|
| 538 |
+
} else {
|
| 539 |
+
// Desktop-specific logic
|
| 540 |
+
document.body.classList.add('desktop-layout');
|
| 541 |
+
console.log('Desktop layout applied.');
|
| 542 |
+
}
|
| 543 |
+
}
|
| 544 |
+
""",
|
| 545 |
+
)
|
| 546 |
|
| 547 |
+
desktop_layout = self._create_desktop_layout()
|
| 548 |
+
mobile_layout = self._create_mobile_layout()
|
| 549 |
+
|
| 550 |
+
# Conditional visibility of the layout
|
| 551 |
+
js_function = """
|
| 552 |
+
() => {
|
| 553 |
+
const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
|
| 554 |
+
if (isMobile) {
|
| 555 |
+
return ['block','none'];
|
| 556 |
+
} else {
|
| 557 |
+
return ['none','block'];
|
| 558 |
+
}
|
| 559 |
+
}
|
| 560 |
+
"""
|
| 561 |
+
|
| 562 |
+
# Set the visibility of the layouts based on the clients device
|
| 563 |
+
mobile_layout.style = {"display": "none"} # Hide by default
|
| 564 |
+
desktop_layout.style = {"display": "none"} # Hide by default
|
| 565 |
+
|
| 566 |
+
gr.on(
|
| 567 |
+
[],
|
| 568 |
+
[],
|
| 569 |
+
[mobile_layout, desktop_layout],
|
| 570 |
+
js_function,
|
| 571 |
+
)
|
| 572 |
|
| 573 |
demo.queue(max_size=20).launch(debug=True, **kwargs)
|
| 574 |
|
| 575 |
def _create_desktop_layout(self):
|
| 576 |
"""Create the desktop layout with sidebar and enhanced styling."""
|
| 577 |
+
with gr.Column(visible=False) as sidebar_demo:
|
| 578 |
with gr.Sidebar():
|
| 579 |
gr.Markdown(
|
| 580 |
"""# 🔍 OpenDeepResearch
|
|
|
|
| 666 |
|
| 667 |
def _create_mobile_layout(self):
|
| 668 |
"""Create the mobile layout (simpler without sidebar)."""
|
| 669 |
+
with gr.Column(visible=False) as simple_demo:
|
| 670 |
gr.Markdown("""#OpenDeepResearch - free the AI agents!""")
|
| 671 |
session_state = gr.State({})
|
| 672 |
stored_messages = gr.State([])
|