Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,14 +10,66 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 10 |
|
| 11 |
# --- Basic Agent Definition ---
|
| 12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 23 |
"""
|
|
|
|
| 10 |
|
| 11 |
# --- Basic Agent Definition ---
|
| 12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 13 |
+
from smolagents import CodeAgent, InferenceClientModel, LiteLLMModel, tool
|
| 14 |
+
import whisper
|
| 15 |
+
from pathlib import Path
|
| 16 |
+
import os
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
@tool
|
| 20 |
+
def reverse_text(text: str) -> str:
|
| 21 |
+
"""
|
| 22 |
+
This is a tool that reverses a text.
|
| 23 |
+
|
| 24 |
+
Args:
|
| 25 |
+
text: The text to be reversed.
|
| 26 |
+
"""
|
| 27 |
+
|
| 28 |
+
return text[::-1]
|
| 29 |
+
|
| 30 |
+
@tool
|
| 31 |
+
def transcribe_audio(filepath: str) -> str:
|
| 32 |
+
"""
|
| 33 |
+
This is a tool that transcribes an audio file
|
| 34 |
+
|
| 35 |
+
Args:
|
| 36 |
+
filepath: the path to the audio file
|
| 37 |
+
"""
|
| 38 |
+
if not Path(filepath).exists():
|
| 39 |
+
return f"Error: {filepath} not found"
|
| 40 |
+
|
| 41 |
+
model = whisper.load_model("turbo")
|
| 42 |
+
return model.transcribe(filepath)["text"]
|
| 43 |
+
|
| 44 |
+
@tool
|
| 45 |
+
def print_file_contents(filepath: str) -> str:
|
| 46 |
+
"""
|
| 47 |
+
This is a tool that prints the contents of a text or code file
|
| 48 |
+
|
| 49 |
+
Args:
|
| 50 |
+
filepath: the path to the file file
|
| 51 |
+
"""
|
| 52 |
+
if not Path(filepath).exists():
|
| 53 |
+
return f"Error: {filepath} not found"
|
| 54 |
+
|
| 55 |
+
with open(filepath) as f:
|
| 56 |
+
return f.read()
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
model_id = "ollama/qwen3:8b"
|
| 60 |
+
|
| 61 |
+
model = LiteLLMModel(model_id,
|
| 62 |
+
num_ctx=8192,
|
| 63 |
+
timeout=1200,
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
agent = CodeAgent(tools=[reverse_text, transcribe_audio, print_file_contents],
|
| 68 |
+
model=model,
|
| 69 |
+
add_base_tools=True,
|
| 70 |
+
max_steps = 8,
|
| 71 |
+
additional_authorized_imports = ["pandas"]
|
| 72 |
+
)
|
| 73 |
|
| 74 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 75 |
"""
|