ressay1973 commited on
Commit
0f96076
·
verified ·
1 Parent(s): dd7a51a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -4
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 whisper
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
- model = whisper.load_model("base")
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)