test-interface / app.py
tommasodelorenzo's picture
Upload folder using huggingface_hub
d46cc41 verified
import gradio as gr
from dotenv import load_dotenv
load_dotenv()
from utils_app import (
_new_chat,
_score_chosen,
_clear_comments,
_comment_submitted,
_load_interface,
_session_id_selected,
)
from main_function import _run_graph
with gr.Blocks(
title="Test Interface",
theme='JohnSmith9982/small_and_pretty',
) as demo:
user_id = gr.Textbox(
visible = False,
)
with gr.Row():
session_id = gr.Dropdown(
choices = [],
value = None,
label = "Chats",
info = "Scegliere la chat",
interactive = True,
visible = True,
allow_custom_value = False,
)
with gr.Row():
new_chat = gr.ClearButton(
value="Nuova Chat",
variant="primary",
)
with gr.Row():
chatbot = gr.Chatbot(
show_copy_button=True
)
with gr.Row():
with gr.Column():
score = gr.Radio(
choices = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"],
show_label = True,
label = "Voto",
visible = True,
)
with gr.Column(visible=False) as comment_column:
comment = gr.Textbox(
label="Commento",
info="Spiega il voto che hai dato",
interactive=True,
)
submit_comment = gr.Button(
value="Invia commento",
variant="primary",
)
close_btn = gr.Button(
value="Chiudi",
variant="secondary",
)
with gr.Row():
input = gr.Textbox(
label = "Messaggio",
placeholder=None,
interactive = True,
)
with gr.Row():
logout_button = gr.Button(
"Logout",
link="/logout"
)
input.submit(
_clear_comments,
outputs = [comment_column, comment],
).then(
lambda: (
gr.Textbox(
interactive=False,
placeholder="Dai un voto alla risposta precedente prima di continuare la conversazione o iniziarne una nuova"),
gr.Radio(visible=False),
gr.Button(interactive=False)
),
outputs = [input, score, new_chat],
).then(
lambda x,y : y + [(x, None)],
inputs = [input, chatbot],
outputs = chatbot
).then(
fn = _run_graph,
inputs = [session_id, input],
outputs = [chatbot],
scroll_to_output = True,
).then(
lambda: (None, gr.Radio(visible=True, value=None)),
outputs = [input, score],
)
score.change(
_score_chosen,
inputs = [session_id, score],
outputs = [comment_column, input, new_chat]
)
submit_comment.click(
_comment_submitted,
inputs = [session_id, comment],
outputs = None
).then(
_clear_comments,
inputs = None,
outputs = [comment_column, comment],
).then(
lambda: (gr.Textbox(interactive=True, placeholder=None), gr.Button(interactive=True), gr.Radio(visible = False)),
outputs = [input, new_chat, score],
)
new_chat.click(
_new_chat,
inputs = [user_id],
outputs = [chatbot, input, comment_column, comment, score, session_id],
)
session_id.change(
_session_id_selected,
inputs = [session_id],
outputs = [chatbot, input, comment_column, comment, score],
)
close_btn.click(
_clear_comments,
inputs = None,
outputs = [comment_column, comment, score, input, new_chat],
)
demo.load(
_load_interface,
None,
[user_id, session_id]
)
if __name__ == "__main__":
from utils_app import _get_users
demo.queue(default_concurrency_limit=20)
demo.launch(
inbrowser = True,
show_error = True,
auth=[(usr["name"], usr["password"]) for usr in _get_users()],
share=True,
)