Leonardo commited on
Commit
c015ef6
·
verified ·
1 Parent(s): a689dca

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +96 -23
app.py CHANGED
@@ -35,33 +35,97 @@ from smolagents.agent_types import AgentText, AgentImage, AgentAudio
35
  from smolagents.gradio_ui import pull_messages_from_step, handle_agent_output_types
36
 
37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  # Constants and configurations
39
  AUTHORIZED_IMPORTS = [
40
- "requests",
41
- "zipfile",
42
- "pandas",
43
- "numpy",
44
- "sympy",
45
- "json",
46
- "bs4",
47
- "pubchempy",
48
- "xml",
49
- "yahoo_finance",
50
- "Bio",
51
- "sklearn",
52
- "scipy",
53
- "pydub",
54
- "PIL",
55
- "chess",
56
- "PyPDF2",
57
- "pptx",
58
- "torch",
59
- "datetime",
60
- "fractions",
61
- "csv",
62
- "clean-text",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  ]
64
 
 
65
  USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36 Edg/119.0.0.0"
66
  BROWSER_CONFIG = {
67
  "viewport_size": 1024 * 5,
@@ -170,6 +234,15 @@ class ToolRegistry:
170
  print(f"✗ Couldn't initialize image generation tool: {e}")
171
  raise
172
 
 
 
 
 
 
 
 
 
 
173
 
174
  def create_agent():
175
  """Creates a fresh agent instance with properly configured tools."""
 
35
  from smolagents.gradio_ui import pull_messages_from_step, handle_agent_output_types
36
 
37
 
38
+ # Constants and configurations
39
+ """Main application for the OpenDeepResearch Gradio interface."""
40
+
41
+ import mimetypes
42
+ import os
43
+ import re
44
+ import shutil
45
+ from typing import Optional
46
+
47
+ from dotenv import load_dotenv
48
+ from huggingface_hub import login
49
+ import gradio as gr
50
+
51
+ from scripts.text_inspector_tool import TextInspectorTool
52
+ from scripts.text_web_browser import (
53
+ ArchiveSearchTool,
54
+ FinderTool,
55
+ FindNextTool,
56
+ PageDownTool,
57
+ PageUpTool,
58
+ SimpleTextBrowser,
59
+ VisitTool,
60
+ )
61
+ from scripts.visual_qa import visualizer
62
+ from scripts.text_cleaner_tool import TextCleanerTool
63
+
64
+ from smolagents import (
65
+ CodeAgent,
66
+ HfApiModel,
67
+ LiteLLMModel,
68
+ OpenAIServerModel,
69
+ TransformersModel,
70
+ GoogleSearchTool,
71
+ Tool,
72
+ )
73
+ from smolagents.agent_types import AgentText, AgentImage, AgentAudio
74
+ from smolagents.gradio_ui import pull_messages_from_step, handle_agent_output_types
75
+
76
+
77
  # Constants and configurations
78
  AUTHORIZED_IMPORTS = [
79
+ "requests", # Web requests (fetching data from the internet)
80
+ "zipfile", # Working with ZIP archives
81
+ "pandas", # Data manipulation and analysis (DataFrames)
82
+ "numpy", # Numerical computing (arrays, linear algebra)
83
+ "sympy", # Symbolic mathematics (algebra, calculus)
84
+ "json", # JSON data serialization/deserialization
85
+ "bs4", # Beautiful Soup for HTML/XML parsing
86
+ "pubchempy", # Accessing PubChem chemical database
87
+ "xml", # XML processing
88
+ "yahoo_finance", # Fetching stock data
89
+ "Bio", # Bioinformatics tools (e.g., sequence analysis)
90
+ "sklearn", # Scikit-learn for machine learning
91
+ "scipy", # Scientific computing (stats, optimization)
92
+ "pydub", # Audio manipulation
93
+ "PIL", # Pillow for image processing
94
+ "chess", # Chess-related functionality
95
+ "PyPDF2", # PDF manipulation
96
+ "pptx", # PowerPoint file manipulation
97
+ "torch", # PyTorch for neural networks
98
+ "datetime", # Date and time handling
99
+ "fractions", # Rational number arithmetic
100
+ "csv", # CSV file reading/writing
101
+ "cleantext", # Text cleaning and normalization
102
+ "os", # Operating system interaction (file system, etc.) VERY IMPORTANT
103
+ "re", # Regular expressions for text processing
104
+ "collections", # Useful data structures (e.g., defaultdict, Counter)
105
+ "math", # Basic mathematical functions
106
+ "random", # Random number generation
107
+ "io", # Input/output streams
108
+ "urllib.parse", # URL parsing and manipulation (safe URL handling)
109
+ "typing", # Support for type hints (improve code clarity)
110
+ "concurrent.futures", # For parallel execution
111
+ "time", # Measuring time
112
+ "tempfile", # Creating temporary files and directories
113
+ # Data Visualization (if needed) - Consider security implications carefully
114
+ "matplotlib", # Plotting library (basic charts) - Consider security implications
115
+ "seaborn", # Statistical data visualization (more advanced) - Consider security implications
116
+ # Web Scraping (more specific/controlled) - Consider ethical implications carefully
117
+ "lxml", # Faster XML/HTML processing (alternative to bs4)
118
+ "selenium", # Automated browser control (for dynamic websites) - HIGH SECURITY RISK
119
+ # Database interaction (if needed) - Handle credentials securely!
120
+ "sqlite3", # SQLite database access
121
+ # "psycopg2", # PostgreSQL adapter if needed
122
+ # Task scheduling
123
+ "schedule", # Allow the agent to schedule tasks
124
+ # Networking
125
+ # "socket", # Networking
126
  ]
127
 
128
+
129
  USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36 Edg/119.0.0.0"
130
  BROWSER_CONFIG = {
131
  "viewport_size": 1024 * 5,
 
234
  print(f"✗ Couldn't initialize image generation tool: {e}")
235
  raise
236
 
237
+ @staticmethod
238
+ def load_clean_text_tool():
239
+ """Initialize and return image generation tools."""
240
+ try:
241
+ return TextCleanerTool
242
+ except Exception as e:
243
+ print(f"✗ Couldn't initialize clean text tool: {e}")
244
+ raise
245
+
246
 
247
  def create_agent():
248
  """Creates a fresh agent instance with properly configured tools."""