Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -23,34 +23,21 @@ ner_pipeline = pipeline("ner", model=ner_model, tokenizer=ner_tokenizer) # Rena
|
|
23 |
|
24 |
|
25 |
@app.route('/transcribe', methods=['POST'])
|
26 |
-
def
|
27 |
-
#
|
28 |
-
if '
|
29 |
-
return jsonify({
|
30 |
|
31 |
-
|
32 |
|
33 |
-
#
|
34 |
-
|
35 |
-
|
36 |
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
file.save(temp_audio)
|
41 |
-
temp_path = temp_audio.name
|
42 |
-
|
43 |
-
# Transcribe the audio using Whisper
|
44 |
-
result = whisper_model.transcribe(temp_path)
|
45 |
-
transcription = result["text"]
|
46 |
-
|
47 |
-
# Clean up the temporary file
|
48 |
-
os.remove(temp_path)
|
49 |
|
50 |
-
return jsonify({'transcription': transcription})
|
51 |
-
|
52 |
-
except Exception as e:
|
53 |
-
return jsonify({'error': str(e)}), 500
|
54 |
|
55 |
|
56 |
|
|
|
23 |
|
24 |
|
25 |
@app.route('/transcribe', methods=['POST'])
|
26 |
+
def transcribe():
|
27 |
+
# Get the audio file from the request
|
28 |
+
if 'audio_file' not in request.files:
|
29 |
+
return jsonify({"error": "No audio file provided"}), 400
|
30 |
|
31 |
+
audio_file = request.files['audio_file']
|
32 |
|
33 |
+
# Save the file to a temporary location
|
34 |
+
audio_file_path = "temp_audio.mp3"
|
35 |
+
audio_file.save(audio_file_path)
|
36 |
|
37 |
+
# Transcribe the audio to text
|
38 |
+
result = whisper_model.transcribe(audio_file_path)
|
39 |
+
return jsonify({"text": result["text"]})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
|
|
|
|
|
|
|
|
|
41 |
|
42 |
|
43 |
|