File size: 3,204 Bytes
4294123
 
 
 
 
 
 
 
17e76f4
4294123
17e76f4
4294123
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17e76f4
4294123
17e76f4
4294123
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17e76f4
4294123
17e76f4
4294123
 
17e76f4
4294123
 
 
 
 
17e76f4
 
4294123
 
 
 
 
 
 
 
 
 
 
 
17e76f4
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
from smolagents import CodeAgent, HfApiModel, DuckDuckGoSearchTool
import yaml

# Import tool CLASSES from the src directory
from src.final_answer_tool import FinalAnswerTool
from src.web_browsing_tool import WebBrowser
from src.file_processing_tool import FileIdentifier
from src.image_processing_tool import ImageProcessor
from src.markdown_table_parser import MarkdownTableParserTool # Updated
from src.python_tool import CodeExecutionTool
from src.speech_to_text import SpeechToTextTool # Updated
from src.spreadsheet_tool import SpreadsheetTool
from src.text_reversal_tool import TextReversalTool
from src.video_processing_tool import VideoProcessingTool

# Import GradioUI from its location
from First_agent_template.Gradio_UI import GradioUI

# Configure the Language Model
model = HfApiModel(
    max_tokens=2096,
    temperature=0.5,
    model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud',
    custom_role_conversions=None,
)

# Instantiate Tools
final_answer_tool = FinalAnswerTool()
web_browsing_tool = WebBrowser() 
file_processing_tool = FileIdentifier() 
image_processing_tool = ImageProcessor() 
markdown_parser_tool = MarkdownTableParserTool() # Updated
python_tool = CodeExecutionTool() 
speech_to_text_tool = SpeechToTextTool() # Updated
spreadsheet_tool = SpreadsheetTool() 
text_reversal_tool = TextReversalTool()
video_processing_tool = VideoProcessingTool() 

# Load Prompts
try:
    with open("prompts.yaml", 'r') as stream:
        prompt_templates = yaml.safe_load(stream)
except FileNotFoundError:
    print("Error: prompts.yaml not found. Please ensure it is in the root project directory.")
    prompt_templates = {} # Fallback to empty templates
except yaml.YAMLError as e:
    print(f"Error parsing prompts.yaml: {e}")
    prompt_templates = {}


# Create the Agent
agent_tools = [
    final_answer_tool,
    web_browsing_tool,
    file_processing_tool,
    image_processing_tool,
    markdown_parser_tool, # Updated
    python_tool,
    speech_to_text_tool, # Updated
    spreadsheet_tool,
    text_reversal_tool,
    video_processing_tool
]

agent = CodeAgent(
    model=model,
    tools=agent_tools,
    max_steps=15,
    verbosity_level=1, 
    name="ComprehensiveQuestionAgent",
    description="An agent equipped with a suite of tools to answer diverse questions from the common_questions.json set.",
    prompt_templates=prompt_templates
)

# Launch the Gradio UI
if __name__ == '__main__':
    print("Launching Gradio UI...")
    try:
        ui = GradioUI(agent)
        ui.launch()
    except Exception as e:
        print(f"Failed to launch Gradio UI: {e}")
        print("Attempting to run agent with a sample query directly...")
        try:
            # This is a placeholder for a direct test if Gradio fails.
            # You might want to load a question from common_questions.json here.
            sample_query = "What is the capital of France and reverse the answer?"
            print(f"Testing agent with query: {sample_query}")
            response = agent.run(sample_query)
            print(f"Agent response: {response}")
        except Exception as agent_e:
            print(f"Error running agent directly: {agent_e}")