import gradio as gr
from main import data_querying, speech_to_text, classify_intent, text_to_speech
def answer_question(text_input=None, audio_input=None):
user_id = "12345"
audio_file_url = None # Initialize this to None outside the try-except block
text_response = None
try:
if audio_input:
print("Audio input received:", audio_input)
input_data = speech_to_text(audio_input)
print("Converted speech to text:", input_data)
response, _ = data_querying(input_data, user_id) # Assuming the first element of the tuple is the response dictionary
print("Generated response:", response)
text_response = response['response'] # Extract the actual text response from the dictionary
audio_file_url = text_to_speech(text_response, user_id) # Convert the response text to speech and get the S3 URL
print("Generated audio URL:", audio_file_url)
elif text_input:
print("Text input received:", text_input)
input_data = text_input
response, _ = data_querying(input_data, user_id) # Assuming the first element of the tuple is the response dictionary
print("Generated response:", response)
text_response = response['response'] # Extract the actual text response from the dictionary
if not input_data:
raise ValueError("No input provided")
except Exception as e:
text_response = str(e)
print("Error:", e)
return text_response, audio_file_url
iface = gr.Interface(
fn=answer_question,
inputs=[
gr.Textbox(lines=2, placeholder="Enter your query here..."),
gr.Audio(type="filepath")
],
outputs=[
gr.Textbox(label="Response Text"),
gr.Audio(label="Response Audio", type="filepath")
],
title="Joi Girlfriend",
description="Girlfriend"
)
if __name__ == "__main__":
iface.launch(share=True, server_name="54.39.104.93", server_port=9000)