Spaces:
Runtime error
Runtime error
import gradio as gr | |
import os | |
from gcp import download_credentials | |
from utils import make_invisible, make_visible, create_folders | |
from backend_functions import get_answer, init_greeting, export_dataframe | |
from dotenv import load_dotenv | |
load_dotenv() | |
download_credentials() | |
create_folders() | |
with gr.Blocks() as main_app: | |
with gr.Tab('Chatbot'): | |
user_id = gr.State('') # id used to find the chat into the database | |
with gr.Column(): | |
with gr.Row(): | |
chat = gr.Chatbot(label="Chatbot Crunchyroll") | |
output_video = gr.Video(interactive=False, label='Video', autoplay=True, height=400) | |
with gr.Column(): | |
with gr.Row(): | |
options_audio = gr.Radio(["XTTS", "Elevenlabs"], label="Audio Generation") | |
output_audio = gr.Audio(interactive=False, label='Audio', autoplay=False) | |
messages = gr.State([]) | |
with gr.Row(): | |
text = gr.Textbox(label='Write your question') | |
with gr.Column(): | |
with gr.Row(): | |
button_text = gr.Button(value='Submit text') | |
clear_button = gr.ClearButton([chat, messages]) | |
with gr.Tab('Times'): | |
columns = ["User Message", "Chatbot Response", "Standalone Question", "Create Embedding", "Query Pinecone", | |
"Context Prompt", "Final Response GPT", "Create Clean Message", "Create Audio", "Create Video", "Final Time"] | |
table_times = gr.DataFrame(headers=columns, visible=False, interactive=False) | |
with gr.Column(): | |
with gr.Row(visible=False) as row_export_csv: | |
export_button = gr.Button(value="Export CSV") | |
csv = gr.File(interactive=False, visible=False) | |
text.submit( | |
fn=get_answer, | |
inputs=[text, chat, messages, output_audio, output_video, table_times, options_audio], | |
outputs=[chat, output_audio, output_video, table_times] | |
).then( | |
lambda: None, None, [text] | |
).then( | |
fn=make_visible, | |
inputs=None, | |
outputs=row_export_csv | |
) | |
button_text.click( | |
fn=get_answer, | |
inputs=[text, chat, messages, output_audio, output_video, table_times, options_audio], | |
outputs=[chat, output_audio, output_video, table_times] | |
).then( | |
lambda: None, None, [text] | |
).then( | |
fn=make_visible, | |
inputs=None, | |
outputs=row_export_csv | |
) | |
export_button.click( | |
fn=export_dataframe, | |
inputs=table_times, | |
outputs=csv | |
) | |
main_app.load(init_greeting, inputs=[chat, messages], outputs=[chat, messages]) | |
main_app.launch(debug=True, auth=(os.environ.get('SPACE_USERNAME'), os.environ.get('SPACE_PASSWORD'))) |