Spaces:
Sleeping
Sleeping
Update agent.py
Browse files
agent.py
CHANGED
|
@@ -87,11 +87,19 @@ class SpeechToTextTool(Tool):
|
|
| 87 |
|
| 88 |
def __init__(self):
|
| 89 |
super().__init__()
|
| 90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
|
| 92 |
def forward(self, audio_path: str) -> str:
|
| 93 |
if not os.path.exists(audio_path):
|
| 94 |
return f"Error: File not found at {audio_path}"
|
|
|
|
|
|
|
| 95 |
try:
|
| 96 |
print(f"Starting transcription for {audio_path}...")
|
| 97 |
result = self.model.transcribe(audio_path)
|
|
|
|
| 87 |
|
| 88 |
def __init__(self):
|
| 89 |
super().__init__()
|
| 90 |
+
try:
|
| 91 |
+
print("Loading whisper model 'base'...")
|
| 92 |
+
self.model = whisper.load_model("base")
|
| 93 |
+
print("Whisper model loaded successfully.")
|
| 94 |
+
except Exception as e:
|
| 95 |
+
print(f"Error loading whisper model: {e}")
|
| 96 |
+
self.model = None
|
| 97 |
|
| 98 |
def forward(self, audio_path: str) -> str:
|
| 99 |
if not os.path.exists(audio_path):
|
| 100 |
return f"Error: File not found at {audio_path}"
|
| 101 |
+
if self.model is None:
|
| 102 |
+
return "Error: Whisper model failed to load during initialization."
|
| 103 |
try:
|
| 104 |
print(f"Starting transcription for {audio_path}...")
|
| 105 |
result = self.model.transcribe(audio_path)
|