Spaces:
Running
Running
File size: 4,149 Bytes
d46cc41 |
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 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
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,
) |