Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -198,11 +198,17 @@ def transcription(file):
|
|
| 198 |
payload = {"buffer": buffer_data}
|
| 199 |
options = PrerecordedOptions(model="nova-2", smart_format=True, diarize=True, redact='ssn')
|
| 200 |
response = deepgram.listen.prerecorded.v("1").transcribe_file(payload, options)
|
| 201 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 202 |
except Exception as e:
|
| 203 |
print(f"Exception: {e}")
|
| 204 |
return None
|
| 205 |
|
|
|
|
|
|
|
| 206 |
ALLOWED_EXTENSIONS = {".mp3", ".wav", ".wma"}
|
| 207 |
|
| 208 |
app.add_middleware(
|
|
@@ -243,6 +249,6 @@ async def transcribe_audio_route(file: UploadFile = File(...)):
|
|
| 243 |
|
| 244 |
transcription_result = transcription(file)
|
| 245 |
if transcription_result:
|
| 246 |
-
return transcription_result
|
| 247 |
else:
|
| 248 |
return {"error": "Transcription failed"}
|
|
|
|
| 198 |
payload = {"buffer": buffer_data}
|
| 199 |
options = PrerecordedOptions(model="nova-2", smart_format=True, diarize=True, redact='ssn')
|
| 200 |
response = deepgram.listen.prerecorded.v("1").transcribe_file(payload, options)
|
| 201 |
+
if response['status'] == "ok":
|
| 202 |
+
paragraphs = [paragraph['transcript'] for paragraph in response['results']['channels'][0]['alternatives'][0]['paragraphs']]
|
| 203 |
+
return " ".join(paragraphs)
|
| 204 |
+
else:
|
| 205 |
+
raise Exception("Transcription failed")
|
| 206 |
except Exception as e:
|
| 207 |
print(f"Exception: {e}")
|
| 208 |
return None
|
| 209 |
|
| 210 |
+
|
| 211 |
+
|
| 212 |
ALLOWED_EXTENSIONS = {".mp3", ".wav", ".wma"}
|
| 213 |
|
| 214 |
app.add_middleware(
|
|
|
|
| 249 |
|
| 250 |
transcription_result = transcription(file)
|
| 251 |
if transcription_result:
|
| 252 |
+
return {"transcription": transcription_result}
|
| 253 |
else:
|
| 254 |
return {"error": "Transcription failed"}
|