|
import os |
|
|
|
from flask import Flask, request, send_file, jsonify, make_response, render_template |
|
|
|
from gradio_client import Client |
|
import tempfile |
|
|
|
|
|
|
|
app = Flask(__name__) |
|
|
|
def process_input(input_text): |
|
|
|
result = "Processed: " + input_text |
|
return result |
|
|
|
@app.route('/', methods=["POST"]) |
|
|
|
def api(): |
|
|
|
if 'audio' not in request.files: |
|
return jsonify({"error": "No audio file provided"}) |
|
|
|
file = request.files['audio'] |
|
filename = request.form.get('filename') |
|
|
|
|
|
temp_dir = tempfile.mkdtemp() |
|
|
|
|
|
destination_path = os.path.join(temp_dir, f"{filename}.wav") |
|
file.save(destination_path) |
|
print(destination_path) |
|
|
|
client = Client("https://xxiani-speechbrain-asr-wav2vec2-transformer-aishells.hf.space/") |
|
result = client.predict( |
|
|
|
destination_path, |
|
api_name="/predict" |
|
) |
|
|
|
os.remove(destination_path) |
|
os.rmdir(temp_dir) |
|
return jsonify({'result': result}) |
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
app.run(host='0.0.0.0', port=23456, debug=False) |