yysb / app.py
xxiani's picture
Update app.py
851bf2f
raw
history blame contribute delete
No virus
1.35 kB
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():
# try:
if 'audio' not in request.files:
return jsonify({"error": "No audio file provided"})
file = request.files['audio']
filename = request.form.get('filename')
# Create a temporary directory
temp_dir = tempfile.mkdtemp()
# Save the audio file to the temporary directory with the specified filename and .wav extension
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, # str (filepath or URL to file) in 'Input' Audio component
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)