|
|
from flask import Flask, request, jsonify |
|
|
from api import UrduWhisper |
|
|
import uuid |
|
|
import os |
|
|
|
|
|
app = Flask(__name__) |
|
|
model = UrduWhisper() |
|
|
|
|
|
UPLOAD = "uploads" |
|
|
os.makedirs(UPLOAD, exist_ok=True) |
|
|
|
|
|
@app.route("/transcribe", methods=["POST"]) |
|
|
def transcribe_audio(): |
|
|
if "file" not in request.files: |
|
|
return jsonify({"error": "No file uploaded"}), 400 |
|
|
|
|
|
file = request.files["file"] |
|
|
filename = f"{UPLOAD}/{uuid.uuid4()}.wav" |
|
|
file.save(filename) |
|
|
|
|
|
text = model.transcribe(filename) |
|
|
os.remove(filename) |
|
|
|
|
|
return jsonify({"text": text}) |
|
|
|
|
|
@app.route("/") |
|
|
def home(): |
|
|
return {"message": "Custom Urdu Whisper API Running!"} |
|
|
|
|
|
if __name__ == "__main__": |
|
|
app.run(host="0.0.0.0", port=5000) |