Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -54,8 +54,11 @@ def preprocess_audio(audio_path):
|
|
| 54 |
@app.post("/transcribe")
|
| 55 |
async def transcribe_audio(file: UploadFile = File(...)):
|
| 56 |
try:
|
| 57 |
-
#
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
| 59 |
temp_file.write(await file.read())
|
| 60 |
temp_path = temp_file.name
|
| 61 |
|
|
@@ -77,6 +80,12 @@ async def transcribe_audio(file: UploadFile = File(...)):
|
|
| 77 |
os.unlink(temp_path)
|
| 78 |
|
| 79 |
return {"transcription": transcription}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
|
| 81 |
except Exception as e:
|
| 82 |
# Clean up the temporary file in case of error
|
|
|
|
| 54 |
@app.post("/transcribe")
|
| 55 |
async def transcribe_audio(file: UploadFile = File(...)):
|
| 56 |
try:
|
| 57 |
+
# Get the original file extension from the uploaded file
|
| 58 |
+
original_extension = os.path.splitext(file.filename)[1]
|
| 59 |
+
|
| 60 |
+
# Save the uploaded file temporarily with the original extension
|
| 61 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=original_extension) as temp_file:
|
| 62 |
temp_file.write(await file.read())
|
| 63 |
temp_path = temp_file.name
|
| 64 |
|
|
|
|
| 80 |
os.unlink(temp_path)
|
| 81 |
|
| 82 |
return {"transcription": transcription}
|
| 83 |
+
except Exception as e:
|
| 84 |
+
# Clean up in case of an error
|
| 85 |
+
if 'temp_path' in locals():
|
| 86 |
+
os.unlink(temp_path)
|
| 87 |
+
raise e
|
| 88 |
+
|
| 89 |
|
| 90 |
except Exception as e:
|
| 91 |
# Clean up the temporary file in case of error
|