from dotenv import load_dotenv load_dotenv() from utils import * from functions import * with (gr.Blocks() as app): user_id = gr.State('') # id used to find the chat into the database with gr.Tab('Option 1'): with gr.Row() as select_author: chat_btn = gr.Button(value='Start chat') # ------------------------------------- Chat API ------------------------------------------- with gr.Row(visible=False) as chatbot: with gr.Column(): with gr.Row(): video = gr.Video(interactive=False, label='Video', autoplay=True) with gr.Row(): output_audio = gr.Audio(interactive=False, label='Audio', autoplay=True) with gr.Row(): checkbox_video = gr.Checkbox( label='Get video', info='Remember that this has a cost' ) checkbox_audio = gr.Checkbox( label='Get only audio', info='This is free but makes API slower' ) radio = gr.Radio( choices=['local', 'remote'], value='local', label='Backend used', visible=False ) with gr.Column(): with gr.Row(): chat = gr.Chatbot(label='Chat') with gr.Row(): with gr.Column(): text = gr.Text(label='Write your question') with gr.Column(): audio = gr.Audio(sources=['microphone'], type='filepath', label='Tell me your question') button_audio = gr.Button(value='Submit audio') # ------------------------------------- Customize prompts ------------------------------------------- with gr.Tab('Option 2'): with gr.Row(): prompt_questions = gr.Textbox(label='Enter you prompt for standalone questions') prompt_main = gr.Textbox(label='Enter your prompt for answerings questions') msg_history = gr.State([]) chatbot_option2 = gr.Chatbot(label='Bella Nosotras') start_button = gr.Button() message = gr.Textbox(visible=False) start_button.click( start_chat, [chatbot_option2, prompt_main], [msg_history, chatbot_option2, start_button, message] ) message.submit( ask_query, [message, chatbot_option2, msg_history, prompt_questions, prompt_main], [message, chatbot_option2, msg_history] ) # -------------------------------------- Actions ----------------------------------------- chat_btn.click( make_invisible, None, select_author ).then( make_visible, None, chatbot ).then( init_chatbot, [chat, radio], [video, chat, user_id] ) text.submit( get_answer_text, [text, chat, user_id, checkbox_video, checkbox_audio, radio], [video, output_audio, chat, text] ) button_audio.click( get_answer_audio, [audio, chat, user_id, checkbox_video, checkbox_audio, radio], [video, output_audio, chat, audio] ) output_audio.stop( lambda: None, None, output_audio ) app.queue() app.launch(debug=True, auth=(os.environ.get('SPACE_USERNAME'), os.environ.get('SPACE_PASSWORD')))