File size: 816 Bytes
06abdb3
 
 
 
 
 
40d9307
06abdb3
f2b84d5
 
 
 
06abdb3
 
 
 
f2b84d5
06abdb3
f2b84d5
06abdb3
 
 
 
 
f2b84d5
06abdb3
 
40d9307
f2b84d5
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from flask import Flask, request, jsonify
import whisper
import os
from tempfile import NamedTemporaryFile

app = Flask(__name__)
model = whisper.load_model("base")

@app.route('/')
def home():
    return "Whisper API is running on Hugging Face!"

@app.route('/ask', methods=['POST'])
def ask():
    if 'file' not in request.files:
        return jsonify({'error': 'No file provided'}), 400

    file = request.files['file']

    with NamedTemporaryFile(delete=False, suffix=".webm") as temp_audio:
        file.save(temp_audio.name)
        try:
            result = model.transcribe(temp_audio.name)
            question = result['text']
            return jsonify({'you_said': question})
        finally:
            os.unlink(temp_audio.name)

# DO NOT add app.run() below. Just expose the app object:
app = app