Spaces:
Runtime error
Runtime error
Create main.py
Browse files
main.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Flask, request, jsonify
|
2 |
+
import whisper
|
3 |
+
import os
|
4 |
+
from tempfile import NamedTemporaryFile
|
5 |
+
|
6 |
+
app = Flask(__name__)
|
7 |
+
model = whisper.load_model("base")
|
8 |
+
|
9 |
+
@app.route('/ask', methods=['POST'])
|
10 |
+
def ask():
|
11 |
+
if 'file' not in request.files:
|
12 |
+
return jsonify({'error': 'No file provided'}), 400
|
13 |
+
|
14 |
+
file = request.files['file']
|
15 |
+
|
16 |
+
with NamedTemporaryFile(delete=False, suffix=".webm") as temp_audio:
|
17 |
+
file.save(temp_audio.name)
|
18 |
+
try:
|
19 |
+
result = model.transcribe(temp_audio.name)
|
20 |
+
question = result['text']
|
21 |
+
# Dummy AI response for now
|
22 |
+
return f"You said: {question}"
|
23 |
+
finally:
|
24 |
+
os.unlink(temp_audio.name)
|
25 |
+
|
26 |
+
if __name__ == '__main__':
|
27 |
+
app.run(debug=True)
|