Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,10 +2,13 @@ from smolagents import CodeAgent, HfApiModel, load_tool, tool
|
|
| 2 |
import datetime
|
| 3 |
import pytz
|
| 4 |
import yaml
|
| 5 |
-
import
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
from Gradio_UI import GradioUI
|
| 8 |
|
|
|
|
|
|
|
|
|
|
| 9 |
# Tool: Convert time between time zones
|
| 10 |
@tool
|
| 11 |
def convert_time(time_str: str, from_tz: str, to_tz: str) -> str:
|
|
@@ -46,7 +49,7 @@ def assign_alert(alert_message: str) -> str:
|
|
| 46 |
return "Alert could not be assigned automatically. Please check manually."
|
| 47 |
|
| 48 |
|
| 49 |
-
# Tool: Transcribe audio and generate a timeline
|
| 50 |
@tool
|
| 51 |
def transcribe_audio(audio_path: str) -> str:
|
| 52 |
"""Transcribe audio and log events with timestamps.
|
|
@@ -54,8 +57,7 @@ def transcribe_audio(audio_path: str) -> str:
|
|
| 54 |
audio_path: Path to the audio file.
|
| 55 |
"""
|
| 56 |
try:
|
| 57 |
-
|
| 58 |
-
result = model.transcribe(audio_path)
|
| 59 |
transcript = result["text"]
|
| 60 |
timestamped_events = [f"{datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')} - {line}" for line in transcript.split('.')]
|
| 61 |
return "\n".join(timestamped_events)
|
|
|
|
| 2 |
import datetime
|
| 3 |
import pytz
|
| 4 |
import yaml
|
| 5 |
+
from transformers import pipeline
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
from Gradio_UI import GradioUI
|
| 8 |
|
| 9 |
+
# Initialize ASR model from Hugging Face
|
| 10 |
+
asr_pipeline = pipeline("automatic-speech-recognition", model="facebook/wav2vec2-large-960h")
|
| 11 |
+
|
| 12 |
# Tool: Convert time between time zones
|
| 13 |
@tool
|
| 14 |
def convert_time(time_str: str, from_tz: str, to_tz: str) -> str:
|
|
|
|
| 49 |
return "Alert could not be assigned automatically. Please check manually."
|
| 50 |
|
| 51 |
|
| 52 |
+
# Tool: Transcribe audio and generate a timeline using Hugging Face ASR
|
| 53 |
@tool
|
| 54 |
def transcribe_audio(audio_path: str) -> str:
|
| 55 |
"""Transcribe audio and log events with timestamps.
|
|
|
|
| 57 |
audio_path: Path to the audio file.
|
| 58 |
"""
|
| 59 |
try:
|
| 60 |
+
result = asr_pipeline(audio_path)
|
|
|
|
| 61 |
transcript = result["text"]
|
| 62 |
timestamped_events = [f"{datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')} - {line}" for line in transcript.split('.')]
|
| 63 |
return "\n".join(timestamped_events)
|