Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,7 @@ import gradio as gr
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
|
|
|
| 6 |
# from langchain.agents import initialize_agent, Tool
|
| 7 |
# from langchain.agents.agent_types import AgentType
|
| 8 |
# from langchain.chat_models import ChatOpenAI
|
|
@@ -15,7 +16,6 @@ import pandas as pd
|
|
| 15 |
# from smolagents.tools import Tool
|
| 16 |
from smolagents import ToolCallingAgent, DuckDuckGoSearchTool, InferenceClientModel, tool
|
| 17 |
|
| 18 |
-
|
| 19 |
# (Keep Constants as is)
|
| 20 |
# --- Constants ---
|
| 21 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
@@ -57,6 +57,26 @@ def read_excel_tool(file_path: str) -> str:
|
|
| 57 |
except Exception as e:
|
| 58 |
return f"Error reading file: {str(e)}"
|
| 59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
# --- Agent defining Class ---
|
| 61 |
class BasicAgent:
|
| 62 |
def __init__(self):
|
|
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
+
import whisper
|
| 7 |
# from langchain.agents import initialize_agent, Tool
|
| 8 |
# from langchain.agents.agent_types import AgentType
|
| 9 |
# from langchain.chat_models import ChatOpenAI
|
|
|
|
| 16 |
# from smolagents.tools import Tool
|
| 17 |
from smolagents import ToolCallingAgent, DuckDuckGoSearchTool, InferenceClientModel, tool
|
| 18 |
|
|
|
|
| 19 |
# (Keep Constants as is)
|
| 20 |
# --- Constants ---
|
| 21 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
|
|
| 57 |
except Exception as e:
|
| 58 |
return f"Error reading file: {str(e)}"
|
| 59 |
|
| 60 |
+
# --- MP3 Audio Transcription Tool ---
|
| 61 |
+
@tool
|
| 62 |
+
def transcribe_audio_tool(audio_path: str) -> str:
|
| 63 |
+
"""
|
| 64 |
+
Transcribes an MP3 (or WAV) audio file using Whisper and returns the full transcription.
|
| 65 |
+
|
| 66 |
+
Args:
|
| 67 |
+
audio_path (str): Full path to the audio file (.mp3 or .wav).
|
| 68 |
+
|
| 69 |
+
Returns:
|
| 70 |
+
str: Transcribed text or error message.
|
| 71 |
+
"""
|
| 72 |
+
try:
|
| 73 |
+
model = whisper.load_model("base") # Or use "small", "medium", or "large" if needed
|
| 74 |
+
|
| 75 |
+
result = model.transcribe(audio_path)
|
| 76 |
+
return result["text"]
|
| 77 |
+
except Exception as e:
|
| 78 |
+
return f"Error transcribing audio: {str(e)}"
|
| 79 |
+
|
| 80 |
# --- Agent defining Class ---
|
| 81 |
class BasicAgent:
|
| 82 |
def __init__(self):
|