Raffaele Terribile
commited on
Rimuovi dipendenze non più necessarie e limita token generati
Browse files- app.py +5 -28
- requirements.txt +1 -5
app.py
CHANGED
@@ -5,27 +5,7 @@ import requests
|
|
5 |
import inspect
|
6 |
import pandas as pd
|
7 |
|
8 |
-
#
|
9 |
-
# MODIFICHE APPORTATE PER RISOLVERE L'ERRORE "generate" NON TROVATO:
|
10 |
-
#
|
11 |
-
# PROBLEMA ORIGINALE:
|
12 |
-
# - Il pipeline di Transformers non è direttamente compatibile con smolagents
|
13 |
-
# - CodeAgent si aspetta un'interfaccia specifica che pipeline non implementa
|
14 |
-
# - L'errore "generate" si verificava perché smolagents cercava metodi non presenti
|
15 |
-
#
|
16 |
-
# SOLUZIONE IMPLEMENTATA:
|
17 |
-
# - Creata classe SimpleLocalModel che fa da wrapper
|
18 |
-
# - Implementa l'interfaccia __call__() che smolagents si aspetta
|
19 |
-
# - Gestisce la conversione dei messaggi e la generazione delle risposte
|
20 |
-
# - Fallback multipli: locale -> remoto -> fisso
|
21 |
-
# =============================================================================
|
22 |
-
|
23 |
-
from smolagents import CodeAgent, TransformersModel, InferenceClientModel, VisitWebpageTool, PythonInterpreterTool, WebSearchTool, WikipediaSearchTool, FinalAnswerTool, Tool, tool
|
24 |
-
# Importazioni per modelli locali (SOLUZIONE per errore "generate"):
|
25 |
-
from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer
|
26 |
-
from litellm import LiteLLM
|
27 |
-
import threading
|
28 |
-
import time
|
29 |
|
30 |
# (Keep Constants as is)
|
31 |
# --- Constants ---
|
@@ -48,7 +28,7 @@ class FirstAgent:
|
|
48 |
### First Agent is the first attempt to develop an agent for the course. ###
|
49 |
def __init__(self):
|
50 |
model_id = "HuggingFaceTB/SmolLM-135M-Instruct"
|
51 |
-
model = TransformersModel(model_id=model_id)
|
52 |
|
53 |
# Inizializza l'agente
|
54 |
self.agent = CodeAgent(
|
@@ -244,14 +224,11 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
244 |
|
245 |
# --- Build Gradio Interface using Blocks ---
|
246 |
with gr.Blocks() as demo:
|
247 |
-
gr.Markdown("#
|
248 |
gr.Markdown(
|
249 |
"""
|
250 |
-
|
251 |
-
|
252 |
-
1. Please clone this space, then modify the code to define your agent's logic, the tools, the necessary packages, etc ...
|
253 |
-
2. Log in to your Hugging Face account using the button below. This uses your HF username for submission.
|
254 |
-
3. Click 'Run Evaluation & Submit All Answers' to fetch questions, run your agent, submit answers, and see the score.
|
255 |
|
256 |
---
|
257 |
**Disclaimers:**
|
|
|
5 |
import inspect
|
6 |
import pandas as pd
|
7 |
|
8 |
+
from smolagents import CodeAgent, TransformersModel, VisitWebpageTool, PythonInterpreterTool, WebSearchTool, WikipediaSearchTool, FinalAnswerTool, Tool, tool # InferenceClientModel, GoogleSearchTool (usa SERPAPI_API_KEY), DuckDuckGoSearchTool
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
# (Keep Constants as is)
|
11 |
# --- Constants ---
|
|
|
28 |
### First Agent is the first attempt to develop an agent for the course. ###
|
29 |
def __init__(self):
|
30 |
model_id = "HuggingFaceTB/SmolLM-135M-Instruct"
|
31 |
+
model = TransformersModel(model_id=model_id, max_new_tokens=2048)
|
32 |
|
33 |
# Inizializza l'agente
|
34 |
self.agent = CodeAgent(
|
|
|
224 |
|
225 |
# --- Build Gradio Interface using Blocks ---
|
226 |
with gr.Blocks() as demo:
|
227 |
+
gr.Markdown("# Raffaele Agent Evaluation Runner")
|
228 |
gr.Markdown(
|
229 |
"""
|
230 |
+
1. Log in to your Hugging Face account using the button below. This uses your HF username for submission.
|
231 |
+
2. Click 'Run Evaluation & Submit All Answers' to fetch questions, run your agent, submit answers, and see the score.
|
|
|
|
|
|
|
232 |
|
233 |
---
|
234 |
**Disclaimers:**
|
requirements.txt
CHANGED
@@ -7,11 +7,7 @@ wikipedia-api
|
|
7 |
transformers
|
8 |
torch
|
9 |
tokenizers
|
10 |
-
# Dipendenze per
|
11 |
-
litellm
|
12 |
-
# Hugging Face Hub per download modelli e API
|
13 |
-
huggingface_hub
|
14 |
-
# Dipendenze per HfApiModel e integrazione completa HF
|
15 |
datasets
|
16 |
accelerate
|
17 |
# Opzionali ma utili
|
|
|
7 |
transformers
|
8 |
torch
|
9 |
tokenizers
|
10 |
+
# Dipendenze per integrazione completa con HF
|
|
|
|
|
|
|
|
|
11 |
datasets
|
12 |
accelerate
|
13 |
# Opzionali ma utili
|