Spaces:
Runtime error
Runtime error
File size: 3,361 Bytes
2c807ae dbcbdf7 2c807ae 4cc32d2 dbcbdf7 4cc32d2 965bab5 4cc32d2 965bab5 4cc32d2 965bab5 dbcbdf7 965bab5 dbcbdf7 965bab5 dbcbdf7 4cc32d2 2c807ae 4cc32d2 2c807ae 4cc32d2 2c807ae 4cc32d2 2c807ae 4cc32d2 |
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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
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')))
|