Update app.py
Browse files
app.py
CHANGED
@@ -1,40 +1,48 @@
|
|
1 |
import os
|
2 |
-
import
|
3 |
-
import tempfile
|
4 |
-
from fastapi import FastAPI, UploadFile, File, HTTPException
|
5 |
from gradio_client import Client
|
|
|
|
|
|
|
6 |
|
7 |
-
app =
|
8 |
|
9 |
def process_input(input_text):
|
10 |
# 处理函数
|
11 |
result = "Processed: " + input_text
|
12 |
return result
|
13 |
|
14 |
-
@app.
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
20 |
# Create a temporary directory
|
21 |
temp_dir = tempfile.mkdtemp()
|
22 |
|
23 |
-
# Save the
|
24 |
-
destination_path = os.path.join(temp_dir,
|
25 |
-
|
26 |
-
|
27 |
|
28 |
client = Client("https://xxiani-speechbrain-asr-wav2vec2-transformer-aishells.hf.space/")
|
29 |
result = client.predict(
|
30 |
-
|
31 |
-
|
|
|
32 |
)
|
33 |
-
|
34 |
os.remove(destination_path)
|
35 |
os.rmdir(temp_dir)
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
|
|
|
|
|
|
1 |
import os
|
2 |
+
from flask import Flask, request, jsonify
|
|
|
|
|
3 |
from gradio_client import Client
|
4 |
+
import tempfile
|
5 |
+
|
6 |
+
|
7 |
|
8 |
+
app = Flask(__name__)
|
9 |
|
10 |
def process_input(input_text):
|
11 |
# 处理函数
|
12 |
result = "Processed: " + input_text
|
13 |
return result
|
14 |
|
15 |
+
@app.route('/', methods=["POST"])
|
16 |
+
@require_api_key
|
17 |
+
def api():
|
18 |
+
# try:
|
19 |
+
if 'audio' not in request.files:
|
20 |
+
return jsonify({"error": "No audio file provided"})
|
21 |
+
|
22 |
+
file = request.files['audio']
|
23 |
+
filename = request.form.get('filename')
|
24 |
+
|
25 |
# Create a temporary directory
|
26 |
temp_dir = tempfile.mkdtemp()
|
27 |
|
28 |
+
# Save the audio file to the temporary directory with the specified filename and .wav extension
|
29 |
+
destination_path = os.path.join(temp_dir, f"{filename}.wav")
|
30 |
+
file.save(destination_path)
|
31 |
+
print(destination_path)
|
32 |
|
33 |
client = Client("https://xxiani-speechbrain-asr-wav2vec2-transformer-aishells.hf.space/")
|
34 |
result = client.predict(
|
35 |
+
|
36 |
+
destination_path, # str (filepath or URL to file) in 'Input' Audio component
|
37 |
+
api_name="/predict"
|
38 |
)
|
39 |
+
|
40 |
os.remove(destination_path)
|
41 |
os.rmdir(temp_dir)
|
42 |
+
return jsonify({'result': result})
|
43 |
+
|
44 |
+
|
45 |
+
|
46 |
|
47 |
+
if __name__ == '__main__':
|
48 |
+
app.run(host='0.0.0.0', port=app.config.get("PORT", 23456), debug=app.config.get("DEBUG", False))
|