Spaces:
Sleeping
Sleeping
| import yaml | |
| from smolagents import CodeAgent, HfApiModel | |
| from tools.final_answer import FinalAnswerTool | |
| from Gradio_UI import GradioUI | |
| import os | |
| from tools.graph_plotter_tool import plot_function_graph | |
| from tools.table_generator_tool import generate_data_table | |
| from tools.statistical_graph_generator import plot_bar_chart, plot_pie_chart, plot_histogram, plot_line_chart | |
| from tools.statistical_graph_analyzer import analyze_dataset | |
| from tools.media_graph_critic import critique_media_graph | |
| from tools.parabola_plotter_tool import plot_parabola_graph | |
| #Tentar implementar Langfuse | |
| #from openinference.instrumentation.smolagents import SmolAgentsInstrumentor | |
| #from langfuse import Langfuse | |
| #print("Configurando a observabilidade com Langfuse...") | |
| # Pega as chaves diretamente das variáveis de ambiente (Secrets do Space) | |
| #os.environ["LANGFUSE_PUBLIC_KEY"] = os.environ.get('LANGFUSE_PUBLIC_KEY') | |
| #os.environ["LANGFUSE_SECRET_KEY"] = os.environ.get('LANGFUSE_SECRET_KEY') | |
| # Inicializa o Langfuse | |
| #langfuse = Langfuse() | |
| # "Instrumenta" a biblioteca smolagents | |
| #SmolAgentsInstrumentor().instrument() | |
| #print("Observabilidade configurada com sucesso.") | |
| final_answer = FinalAnswerTool() | |
| # Configuração do Modelo | |
| #testar outros modelos: meta-llama/Llama-3.1-70B-Instruct e Gemma 3-27B | |
| model = HfApiModel( | |
| # AUMENTAR OS TOKENS para acomodar respostas mais longas com várias questões | |
| max_tokens=4096, | |
| temperature=0.6, | |
| model_id='Qwen/Qwen2.5-VL-32B-Instruct', | |
| ) | |
| # Carregar nosso novo prompt especializado em gerar questões. | |
| with open("prompts.yaml", 'r', encoding='utf-8') as stream: | |
| prompt_templates = yaml.safe_load(stream) | |
| # Criação do Agente | |
| agent = CodeAgent( | |
| model=model, | |
| tools=[ | |
| final_answer, | |
| plot_parabola_graph, | |
| plot_bar_chart, | |
| plot_pie_chart, | |
| plot_histogram, | |
| plot_line_chart, | |
| analyze_dataset, | |
| generate_data_table, | |
| critique_media_graph | |
| ], | |
| max_steps=5, | |
| verbosity_level=1, | |
| prompt_templates=prompt_templates | |
| ) | |
| # Interface Gráfica | |
| # Lança a interface Gradio para interagir com o agente. | |
| GradioUI(agent).launch() |