Leonardo commited on
Commit
1a9f532
·
verified ·
1 Parent(s): baae88b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -18
app.py CHANGED
@@ -1,26 +1,14 @@
1
- import argparse
2
  import json
3
  import mimetypes # Added missing import
4
  import os
5
  import re # Added missing import
6
  import shutil # Added missing import
7
- import threading
8
- from concurrent.futures import ThreadPoolExecutor, as_completed
9
- from datetime import datetime
10
- from pathlib import Path
11
  from typing import Dict, List, Optional, Any
12
 
13
- import datasets
14
- import pandas as pd
15
  from dotenv import load_dotenv
16
  from huggingface_hub import login
17
  import gradio as gr
18
 
19
- from scripts.reformulator import prepare_response
20
- from scripts.run_agents import (
21
- get_single_file_description,
22
- get_zip_description,
23
- )
24
  from scripts.text_inspector_tool import TextInspectorTool
25
  from scripts.text_web_browser import (
26
  ArchiveSearchTool,
@@ -34,16 +22,13 @@ from scripts.text_web_browser import (
34
  from scripts.visual_qa import visualizer
35
 
36
  # from scripts.flux_lora_tool import FluxLoRATool
37
- from tqdm import tqdm
38
 
39
  from smolagents import (
40
  CodeAgent,
41
  HfApiModel,
42
  LiteLLMModel,
43
- Model,
44
  OpenAIServerModel, # Added missing model
45
  TransformersModel, # Added missing model
46
- ToolCallingAgent,
47
  Tool,
48
  )
49
  from smolagents.agent_types import AgentText, AgentImage, AgentAudio
@@ -283,7 +268,7 @@ class ToolRegistry:
283
 
284
  # Agent creation in a factory function
285
  def create_agent():
286
- """Creates a fresh agent instance for each session."""
287
  # Initialize model
288
  model = LiteLLMModel(
289
  custom_role_conversions=custom_role_conversions,
@@ -294,12 +279,23 @@ def create_agent():
294
  text_limit = 20000
295
  browser = SimpleTextBrowser(**BROWSER_CONFIG)
296
 
 
297
  web_tools = ToolRegistry.load_web_tools(model, browser, text_limit)
298
  gemma_vision_tool = ToolRegistry.load_vision_tools()
299
 
 
 
 
 
 
 
 
 
 
 
300
  return CodeAgent(
301
  model=model,
302
- tools=([visualizer] + web_tools, gemma_vision_tool), # Fixed the missing comma
303
  max_steps=10,
304
  verbosity_level=1,
305
  additional_authorized_imports=AUTHORIZED_IMPORTS,
@@ -536,7 +532,7 @@ class GradioUI:
536
  # Add session state to store session-specific data
537
  session_state = gr.State({}) # Initialize empty state for each session
538
  stored_messages = gr.State([])
539
- if not "file_uploads_log" in locals():
540
  file_uploads_log = gr.State([])
541
 
542
  chatbot = gr.Chatbot(
 
 
1
  import json
2
  import mimetypes # Added missing import
3
  import os
4
  import re # Added missing import
5
  import shutil # Added missing import
 
 
 
 
6
  from typing import Dict, List, Optional, Any
7
 
 
 
8
  from dotenv import load_dotenv
9
  from huggingface_hub import login
10
  import gradio as gr
11
 
 
 
 
 
 
12
  from scripts.text_inspector_tool import TextInspectorTool
13
  from scripts.text_web_browser import (
14
  ArchiveSearchTool,
 
22
  from scripts.visual_qa import visualizer
23
 
24
  # from scripts.flux_lora_tool import FluxLoRATool
 
25
 
26
  from smolagents import (
27
  CodeAgent,
28
  HfApiModel,
29
  LiteLLMModel,
 
30
  OpenAIServerModel, # Added missing model
31
  TransformersModel, # Added missing model
 
32
  Tool,
33
  )
34
  from smolagents.agent_types import AgentText, AgentImage, AgentAudio
 
268
 
269
  # Agent creation in a factory function
270
  def create_agent():
271
+ """Creates a fresh agent instance with properly configured tools."""
272
  # Initialize model
273
  model = LiteLLMModel(
274
  custom_role_conversions=custom_role_conversions,
 
279
  text_limit = 20000
280
  browser = SimpleTextBrowser(**BROWSER_CONFIG)
281
 
282
+ # Collect all tools in a single list
283
  web_tools = ToolRegistry.load_web_tools(model, browser, text_limit)
284
  gemma_vision_tool = ToolRegistry.load_vision_tools()
285
 
286
+ # Combine all tools into a single list (not a tuple)
287
+ all_tools = [visualizer] + web_tools + [gemma_vision_tool]
288
+
289
+ # Validate tools before creating agent
290
+ for tool in all_tools:
291
+ if not isinstance(tool, Tool):
292
+ raise ValueError(
293
+ f"Invalid tool type: {type(tool)}. All tools must be instances of Tool class."
294
+ )
295
+
296
  return CodeAgent(
297
  model=model,
298
+ tools=all_tools, # Pass a single list containing all tools
299
  max_steps=10,
300
  verbosity_level=1,
301
  additional_authorized_imports=AUTHORIZED_IMPORTS,
 
532
  # Add session state to store session-specific data
533
  session_state = gr.State({}) # Initialize empty state for each session
534
  stored_messages = gr.State([])
535
+ if "file_uploads_log" not in locals():
536
  file_uploads_log = gr.State([])
537
 
538
  chatbot = gr.Chatbot(