Spaces:
Sleeping
Sleeping
File size: 1,022 Bytes
9314fc1 |
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 32 33 34 35 36 37 38 39 40 41 |
import os
import uuid
from flask import Flask, flash, render_template, request
from flask_cors import CORS
from modules import Module
model = Module()
app = Flask(__name__)
CORS(app)
app.secret_key = "Testing"
@app.route('/')
def index():
flash(" Welcome to My Website")
return render_template('index.html')
@app.route('/audio_to_text/')
def audio_to_text():
flash(" Press Start to start recording audio and press Stop to end recording audio")
return render_template('audio_to_text.html')
@app.route('/audio', methods=['POST'])
def audio():
try:
output_file = f"./tmp/{uuid.uuid4()}.wav"
open(output_file, 'wb').write(request.data)
text, emotion = model.predict(audio_path=output_file)
os.remove(output_file)
return_text = f" Transcription: {text} <br> Emotion: {emotion} "
except Exception:
return_text = " Sorry!!!! Voice not Detected "
return return_text
if __name__ == "__main__":
app.run(debug=True, port=7860, host='0.0.0.0')
|