test-spase / app.py
taras5500's picture
Update app.py
497096a verified
import gradio as gr
import spaces
from models import asr_bot, llm_bot, tts_bot
audio_file = "./titty-sprinkles-101soundboards.mp3"
def llm_request(text):
if text:
system_message = """You are an AI assistant.
Provide clear and concise answers to user queries, ensuring responses are no longer than 128 tokens.
Aim to be informative, accurate, and helpful within this limit."""
return llm_bot.call(text, system_message)
print("error: llm respond Null")
@spaces.GPU(enable_queue=True)
def asr_request(audio):
text = asr_bot.call(audio)
return text
def tts_request(text):
if text:
audio = tts_bot.call(text)
return audio
print("error: no text provided")
def main(message):
print(message)
#send request to recognition ASR -> return text
converted_text = asr_request(message)
#send request to LLM -> return text
llm_answer = llm_request(converted_text)
print(llm_answer)
print(type(llm_answer))
#send request to TTS -> return audio
tts_answer = tts_request(llm_answer)
print(tts_answer)
return tts_answer
d = gr.Interface(
main,
inputs=gr.Audio(sources="microphone", type="filepath"),
outputs="audio"
)
d.queue()
d.launch()