Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -22,19 +22,23 @@ ner_pipeline = pipeline("ner", model=ner_model, tokenizer=ner_tokenizer) # Rena
|
|
| 22 |
|
| 23 |
@app.route('/transcribe', methods=['POST'])
|
| 24 |
def transcribe():
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
-
|
|
|
|
| 30 |
|
| 31 |
-
|
| 32 |
-
audio_file_path = "temp_audio.mp3"
|
| 33 |
-
audio_file.save(audio_file_path)
|
| 34 |
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
|
| 39 |
|
| 40 |
|
|
|
|
| 22 |
|
| 23 |
@app.route('/transcribe', methods=['POST'])
|
| 24 |
def transcribe():
|
| 25 |
+
try:
|
| 26 |
+
# Read the raw audio bytes
|
| 27 |
+
audio_bytes = request.data # Get raw bytes from request
|
| 28 |
+
if not audio_bytes:
|
| 29 |
+
return jsonify({"error": "No audio data provided"}), 400
|
| 30 |
+
|
| 31 |
+
# Convert bytes to a file-like object
|
| 32 |
+
audio_file = io.BytesIO(audio_bytes)
|
| 33 |
|
| 34 |
+
# Transcribe the audio
|
| 35 |
+
result = whisper_model.transcribe(audio_file)
|
| 36 |
|
| 37 |
+
return jsonify({"text": result["text"]})
|
|
|
|
|
|
|
| 38 |
|
| 39 |
+
except Exception as e:
|
| 40 |
+
print("Error:", str(e)) # Log the error
|
| 41 |
+
return jsonify({"error": "Internal Server Error", "details": str(e)}), 500
|
| 42 |
|
| 43 |
|
| 44 |
|