Update app.py
Browse files
app.py
CHANGED
|
@@ -11,10 +11,8 @@ from smolagents import CodeAgent, HfApiModel, tool
|
|
| 11 |
def get_current_time_in_timezone(timezone: Optional[str] = None) -> str:
|
| 12 |
"""
|
| 13 |
Returns the current time. If a timezone is provided, it is noted in the message.
|
| 14 |
-
|
| 15 |
Args:
|
| 16 |
timezone: An optional timezone name or location.
|
| 17 |
-
|
| 18 |
Returns:
|
| 19 |
A string with the current time.
|
| 20 |
"""
|
|
@@ -28,10 +26,8 @@ def get_current_time_in_timezone(timezone: Optional[str] = None) -> str:
|
|
| 28 |
def parse_csv(file_path: str) -> str:
|
| 29 |
"""
|
| 30 |
Parses a CSV file and returns the first few rows.
|
| 31 |
-
|
| 32 |
Args:
|
| 33 |
file_path: Path to the CSV file to be parsed.
|
| 34 |
-
|
| 35 |
Returns:
|
| 36 |
A preview of the first rows.
|
| 37 |
"""
|
|
@@ -43,10 +39,8 @@ def parse_csv(file_path: str) -> str:
|
|
| 43 |
def transcribe_audio(audio_path: str) -> str:
|
| 44 |
"""
|
| 45 |
Transcribes spoken words in an audio file.
|
| 46 |
-
|
| 47 |
Args:
|
| 48 |
audio_path: Path to the .mp3 or .wav file.
|
| 49 |
-
|
| 50 |
Returns:
|
| 51 |
A transcription of the audio.
|
| 52 |
"""
|
|
@@ -73,7 +67,12 @@ class BasicAgent:
|
|
| 73 |
print("✅ Agent initialized with all tools")
|
| 74 |
|
| 75 |
def __call__(self, question: str) -> str:
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
# === Evaluation Logic ===
|
| 79 |
def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
@@ -147,6 +146,7 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
| 147 |
f"Overall Score: {result_data.get('score', 'N/A')}% "
|
| 148 |
f"({result_data.get('correct_count', '?')}/{result_data.get('total_attempted', '?')} correct)\n"
|
| 149 |
f"Message: {result_data.get('message', 'No message received.')}"
|
|
|
|
| 150 |
)
|
| 151 |
return final_status, pd.DataFrame(results_log)
|
| 152 |
except Exception as e:
|
|
|
|
| 11 |
def get_current_time_in_timezone(timezone: Optional[str] = None) -> str:
|
| 12 |
"""
|
| 13 |
Returns the current time. If a timezone is provided, it is noted in the message.
|
|
|
|
| 14 |
Args:
|
| 15 |
timezone: An optional timezone name or location.
|
|
|
|
| 16 |
Returns:
|
| 17 |
A string with the current time.
|
| 18 |
"""
|
|
|
|
| 26 |
def parse_csv(file_path: str) -> str:
|
| 27 |
"""
|
| 28 |
Parses a CSV file and returns the first few rows.
|
|
|
|
| 29 |
Args:
|
| 30 |
file_path: Path to the CSV file to be parsed.
|
|
|
|
| 31 |
Returns:
|
| 32 |
A preview of the first rows.
|
| 33 |
"""
|
|
|
|
| 39 |
def transcribe_audio(audio_path: str) -> str:
|
| 40 |
"""
|
| 41 |
Transcribes spoken words in an audio file.
|
|
|
|
| 42 |
Args:
|
| 43 |
audio_path: Path to the .mp3 or .wav file.
|
|
|
|
| 44 |
Returns:
|
| 45 |
A transcription of the audio.
|
| 46 |
"""
|
|
|
|
| 67 |
print("✅ Agent initialized with all tools")
|
| 68 |
|
| 69 |
def __call__(self, question: str) -> str:
|
| 70 |
+
response = self.agent.run(question)
|
| 71 |
+
if "Final Answer:" not in response:
|
| 72 |
+
# Add fallback final answer if missing
|
| 73 |
+
last_line = response.strip().split("\n")[-1]
|
| 74 |
+
response += f"\nFinal Answer: {last_line}"
|
| 75 |
+
return response
|
| 76 |
|
| 77 |
# === Evaluation Logic ===
|
| 78 |
def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
|
|
| 146 |
f"Overall Score: {result_data.get('score', 'N/A')}% "
|
| 147 |
f"({result_data.get('correct_count', '?')}/{result_data.get('total_attempted', '?')} correct)\n"
|
| 148 |
f"Message: {result_data.get('message', 'No message received.')}"
|
| 149 |
+
|
| 150 |
)
|
| 151 |
return final_status, pd.DataFrame(results_log)
|
| 152 |
except Exception as e:
|