ruimartinscorrea commited on
Commit
19647dc
·
verified ·
1 Parent(s): 1cfcd2a

Update src/webui/webui_manager.py

Browse files
Files changed (1) hide show
  1. src/webui/webui_manager.py +34 -97
src/webui/webui_manager.py CHANGED
@@ -1,97 +1,34 @@
1
- import json
2
- from collections.abc import Generator
3
- from typing import TYPE_CHECKING
4
- import os
5
- import gradio as gr
6
- from datetime import datetime
7
- from typing import Optional, Dict, List
8
- import uuid
9
- import asyncio
10
- import time
11
-
12
- from gradio.components import Component
13
- from browser_use.browser import Browser
14
- from browser_use.browser.context import BrowserContext
15
- from browser_use.agent.service import Agent
16
- from src.browser.custom_browser import CustomBrowser
17
- from src.browser.custom_context import CustomBrowserContext
18
- from src.controller.custom_controller import CustomController
19
- from src.agent.deep_research.deep_research_agent import DeepResearchAgent
20
-
21
- class WebuiManager:
22
- def __init__(self, settings_save_dir: str = "./tmp/webui_settings"):
23
- self.id_to_component: dict[str, Component] = {}
24
- self.component_to_id: dict[Component, str] = {}
25
-
26
- self.settings_save_dir = settings_save_dir
27
- os.makedirs(self.settings_save_dir, exist_ok=True)
28
-
29
- def init_browser_use_agent(self) -> None:
30
- self.bu_agent: Optional[Agent] = None
31
- self.bu_browser: Optional[CustomBrowser] = None
32
- self.bu_browser_context: Optional[CustomBrowserContext] = None
33
- self.bu_controller: Optional[CustomController] = None
34
- self.bu_chat_history: List[Dict[str, Optional[str]]] = []
35
- self.bu_response_event: Optional[asyncio.Event] = None
36
- self.bu_user_help_response: Optional[str] = None
37
- self.bu_current_task: Optional[asyncio.Task] = None
38
- self.bu_agent_task_id: Optional[str] = None
39
-
40
- def init_deep_research_agent(self) -> None:
41
- self.dr_agent: Optional[DeepResearchAgent] = None
42
- self.dr_current_task = None
43
- self.dr_agent_task_id: Optional[str] = None
44
- self.dr_save_dir: Optional[str] = None
45
-
46
- def add_components(self, tab_name: str, components_dict: dict[str, "Component"]) -> None:
47
- for comp_name, component in components_dict.items():
48
- comp_id = f"{tab_name}.{comp_name}"
49
- self.id_to_component[comp_id] = component
50
- self.component_to_id[component] = comp_id
51
-
52
- def get_components(self) -> list["Component"]:
53
- return list(self.id_to_component.values())
54
-
55
- def get_component_by_id(self, comp_id: str) -> "Component":
56
- return self.id_to_component[comp_id]
57
-
58
- def get_id_by_component(self, comp: "Component") -> str:
59
- return self.component_to_id[comp]
60
-
61
- def save_config(self, components: Dict["Component", str]) -> None:
62
- cur_settings = {}
63
- for comp in components:
64
- if not isinstance(comp, gr.Button) and not isinstance(comp, gr.File) and str(
65
- getattr(comp, "interactive", True)).lower() != "false":
66
- comp_id = self.get_id_by_component(comp)
67
- cur_settings[comp_id] = components[comp]
68
-
69
- config_name = datetime.now().strftime("%Y%m%d-%H%M%S")
70
- with open(os.path.join(self.settings_save_dir, f"{config_name}.json"), "w") as fw:
71
- json.dump(cur_settings, fw, indent=4)
72
-
73
- return os.path.join(self.settings_save_dir, f"{config_name}.json")
74
-
75
- def load_config(self, config_path: str):
76
- with open(config_path, "r") as fr:
77
- ui_settings = json.load(fr)
78
-
79
- update_components = {}
80
- for comp_id, comp_val in ui_settings.items():
81
- if comp_id in self.id_to_component:
82
- comp = self.id_to_component[comp_id]
83
- if comp.__class__.__name__ == "Chatbot":
84
- update_components[comp] = comp.__class__(value=comp_val, type="messages")
85
- else:
86
- update_components[comp] = comp.__class__(value=comp_val)
87
- if comp_id == "agent_settings.planner_llm_provider":
88
- yield update_components
89
- time.sleep(0.1)
90
-
91
- config_status = self.id_to_component["load_save_config.config_status"]
92
- update_components.update(
93
- {
94
- config_status: config_status.__class__(value=f"Successfully loaded config: {config_path}")
95
- }
96
- )
97
- yield update_components
 
1
+ # UI
2
+ gradio==5.27.0
3
+ pyperclip==1.9.0
4
+
5
+ # Web scraping / HTML helpers
6
+ trafilatura
7
+ lxml_html_clean
8
+ html2text
9
+ beautifulsoup4
10
+ uuid-utils
11
+ json-repair
12
+
13
+ # Core Python packages
14
+ pydantic>=2.9.2
15
+ pydantic-settings>=2.6.1
16
+ fastapi>=0.115.5
17
+ python-dotenv
18
+
19
+ # Browser / UI helpers
20
+ browser-use>=0.1.48
21
+ playwright>=1.49.1
22
+
23
+ # LangChain ecosystem (working combination)
24
+ langchain==0.3.48
25
+ langchain-core==0.3.48
26
+ langchain-community>=0.3.14,<0.4.0
27
+ langchain-mcp-adapters>=0.2.0,<0.3.0
28
+ mcp>=1.0.0
29
+ langchain-mistralai==0.2.4
30
+ langchain-ibm==0.3.10
31
+ langgraph==0.3.34
32
+
33
+ # Local / custom modules
34
+ MainContentExtractor==0.0.4