Agent_UB / app.py
t-pris's picture
Upload folder using huggingface_hub
7b295db verified
import gradio as gr
from agent import Agent, process_data, process_retrievers
import torch
from markdown_it import MarkdownIt
import json
def init_agent():
print("init agent ......")
DATA_DIR = "data_websites"
PATH_SAVE_CHUNKS = "chunks_saved.json"
PATH_SAVE_CONTEXT = "chunks_with_context.json"
PATH_IDX = "index_faiss_data_sh"
PATH_IDX_CONTEXT = "index_faiss_context_sh"
PATH_IDX_CONTEXT_AND_WT = "index_faiss_context_and_wt_sh"
# embedding_model_names = ["Geotrend/distilbert-base-en-fr-cased"]
embedding_model_names = []
use_context = False
reformulation = False
use_HyDE = False
use_HyDE_cut = False
use_context_and_wt = True
ask_again = False
TOP_K = 10
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
list_dir, chunks = process_data(DATA_DIR, PATH_SAVE_CHUNKS, PATH_SAVE_CONTEXT, use_context_and_wt, use_context)
embedding_models, BM25_retriever = process_retrievers(embedding_model_names, chunks, TOP_K, use_context,
use_context_and_wt, PATH_IDX, PATH_IDX_CONTEXT,
PATH_IDX_CONTEXT_AND_WT, device)
agent = Agent(list_dir, chunks, embedding_models, BM25_retriever, TOP_K, reformulation,
use_HyDE, use_HyDE_cut, ask_again)
return agent
def respond(agent, user_input, history, comments, likes):
reply, sources = agent.get_a_reply(user_input)
bot_response = str(reply) + "\n\n\nℹ️ *Retrouvez davantage d'informations sur la page du site internet de l'université*:\n"+ "\n".join(f"- [{src}]({src})" for src in sources)
# bot_response = f"Echo: {user_input}"
history.append(("user", user_input))
history.append(("bot", bot_response))
return agent, "", update_html(history, comments, likes), history, comments
def add_comment(comment_input, comments, history, likes):
com = comment_input.split(" : ")
message_index = int(com[0])
comment_text = com[1]
if message_index in comments:
comments[message_index] += [comment_text]
else:
comments[message_index] = [comment_text]
print(data)
return update_html(history, comments, likes), comments
def handle_feedback(history, comments, feedback, likes):
com = feedback.split(" : ")
message_index = int(com[0])
like_val = int(com[1])
if message_index != -1:
if message_index in likes and likes[message_index] == like_val:
# likes[message_index] = 0
likes.pop(message_index)
else:
likes[message_index] = like_val
print(data)
feedback = "-1 : 0"
return update_html(history, comments, likes), feedback, likes
def update_html(history, comments, likes):
like_empty = """
<svg width="5%" height="5%" viewBox="0 0 12 12" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M9.75 4.74023H7.5V2.49023C7.4997 2.19196 7.38108 1.90598 7.17017 1.69507C6.95925 1.48415 6.67328 1.36553 6.375 1.36523H5.57512C5.39481 1.366 5.22074 1.43138 5.08451 1.54952C4.94828 1.66766 4.85891 1.83072 4.83262 2.00911L4.51575 4.22798L3.17438 6.24023H0.75V11.4902H8.625C9.32089 11.4892 9.98799 11.2124 10.4801 10.7203C10.9721 10.2282 11.249 9.56112 11.25 8.86523V6.24023C11.2495 5.84256 11.0913 5.46132 10.8101 5.18012C10.5289 4.89893 10.1477 4.74073 9.75 4.74023ZM3 10.7402H1.5V6.99023H3V10.7402ZM10.5 8.86523C10.4994 9.36233 10.3017 9.8389 9.95017 10.1904C9.59867 10.5419 9.1221 10.7396 8.625 10.7402H3.75V6.72886L5.23425 4.50248L5.5755 2.11523H6.375C6.47446 2.11523 6.56984 2.15474 6.64017 2.22507C6.71049 2.2954 6.75 2.39078 6.75 2.49023V5.49023H9.75C9.94882 5.49053 10.1394 5.56965 10.28 5.71023C10.4206 5.85082 10.4997 6.04141 10.5 6.24023V8.86523Z" fill="currentColor"></path>
</svg>
"""
unlike_empty = """
<svg width="5%" height="5%" viewBox="0 0 12 12" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M2.25 8.11523H4.5V10.3652C4.5003 10.6635 4.61892 10.9495 4.82983 11.1604C5.04075 11.3713 5.32672 11.4899 5.625 11.4902H6.42488C6.60519 11.4895 6.77926 11.4241 6.91549 11.3059C7.05172 11.1878 7.14109 11.0248 7.16737 10.8464L7.48425 8.62748L8.82562 6.61523H11.25V1.36523H3.375C2.67911 1.36623 2.01201 1.64311 1.51994 2.13517C1.02787 2.62724 0.750992 3.29435 0.75 3.99023V6.61523C0.750496 7.01291 0.908691 7.39415 1.18989 7.67535C1.47109 7.95654 1.85233 8.11474 2.25 8.11523ZM9 2.11523H10.5V5.86523H9V2.11523ZM1.5 3.99023C1.5006 3.49314 1.69833 3.01657 2.04983 2.66507C2.40133 2.31356 2.8779 2.11583 3.375 2.11523H8.25V6.12661L6.76575 8.35298L6.4245 10.7402H5.625C5.52554 10.7402 5.43016 10.7007 5.35983 10.6304C5.28951 10.5601 5.25 10.4647 5.25 10.3652V7.36523H2.25C2.05118 7.36494 1.86059 7.28582 1.72 7.14524C1.57941 7.00465 1.5003 6.81406 1.5 6.61523V3.99023Z" fill="currentColor"></path>
</svg>
"""
like_filled = """
<svg width="5%" height="5%" viewBox="0 0 12 12" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M0.75 6.24023H2.625V11.4902H0.75V6.24023ZM8.625 11.4902H3.375V5.93911L4.51575 4.22798L4.83263 2.00911C4.85892 1.83065 4.94834 1.66754 5.08465 1.5494C5.22096 1.43125 5.39512 1.36591 5.5755 1.36523H5.625C5.92328 1.36553 6.20925 1.48415 6.42017 1.69507C6.63108 1.90598 6.7497 2.19196 6.75 2.49023V4.74023H9.75C10.1477 4.74073 10.5289 4.89893 10.8101 5.18012C11.0913 5.46132 11.2495 5.84256 11.25 6.24023V8.86523C11.249 9.56112 10.9721 10.2282 10.4801 10.7203C9.98799 11.2124 9.32089 11.4892 8.625 11.4902Z" fill="currentColor"></path>
</svg>
"""
unlike_filled = """
<svg width="5%" height="5%" viewBox="0 0 12 12" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M11.25 6.61523H9.375V1.36523H11.25V6.61523ZM3.375 1.36523H8.625V6.91636L7.48425 8.62748L7.16737 10.8464C7.14108 11.0248 7.05166 11.1879 6.91535 11.3061C6.77904 11.4242 6.60488 11.4896 6.4245 11.4902H6.375C6.07672 11.4899 5.79075 11.3713 5.57983 11.1604C5.36892 10.9495 5.2503 10.6635 5.25 10.3652V8.11523H2.25C1.85233 8.11474 1.47109 7.95654 1.18989 7.67535C0.908691 7.39415 0.750496 7.01291 0.75 6.61523V3.99023C0.750992 3.29435 1.02787 2.62724 1.51994 2.13517C2.01201 1.64311 2.67911 1.36623 3.375 1.36523Z" fill="currentColor"></path>
</svg>
"""
send = """
<svg viewBox="2 0 20 20" width="100%" height="100%" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M19.1168 12.1484C19.474 12.3581 19.9336 12.2384 20.1432 11.8811C20.3528 11.5238 20.2331 11.0643 19.8758 10.8547L19.1168 12.1484ZM6.94331 4.13656L6.55624 4.77902L6.56378 4.78344L6.94331 4.13656ZM5.92408 4.1598L5.50816 3.5357L5.50816 3.5357L5.92408 4.1598ZM5.51031 5.09156L4.76841 5.20151C4.77575 5.25101 4.78802 5.29965 4.80505 5.34671L5.51031 5.09156ZM7.12405 11.7567C7.26496 12.1462 7.69495 12.3477 8.08446 12.2068C8.47397 12.0659 8.67549 11.6359 8.53458 11.2464L7.12405 11.7567ZM19.8758 12.1484C20.2331 11.9388 20.3528 11.4793 20.1432 11.122C19.9336 10.7648 19.474 10.6451 19.1168 10.8547L19.8758 12.1484ZM6.94331 18.8666L6.56375 18.2196L6.55627 18.2241L6.94331 18.8666ZM5.92408 18.8433L5.50815 19.4674H5.50815L5.92408 18.8433ZM5.51031 17.9116L4.80505 17.6564C4.78802 17.7035 4.77575 17.7521 4.76841 17.8016L5.51031 17.9116ZM8.53458 11.7567C8.67549 11.3672 8.47397 10.9372 8.08446 10.7963C7.69495 10.6554 7.26496 10.8569 7.12405 11.2464L8.53458 11.7567ZM19.4963 12.2516C19.9105 12.2516 20.2463 11.9158 20.2463 11.5016C20.2463 11.0873 19.9105 10.7516 19.4963 10.7516V12.2516ZM7.82931 10.7516C7.4151 10.7516 7.07931 11.0873 7.07931 11.5016C7.07931 11.9158 7.4151 12.2516 7.82931 12.2516V10.7516ZM19.8758 10.8547L7.32284 3.48968L6.56378 4.78344L19.1168 12.1484L19.8758 10.8547ZM7.33035 3.49414C6.76609 3.15419 6.05633 3.17038 5.50816 3.5357L6.34 4.78391C6.40506 4.74055 6.4893 4.73863 6.55627 4.77898L7.33035 3.49414ZM5.50816 3.5357C4.95998 3.90102 4.67184 4.54987 4.76841 5.20151L6.25221 4.98161C6.24075 4.90427 6.27494 4.82727 6.34 4.78391L5.50816 3.5357ZM4.80505 5.34671L7.12405 11.7567L8.53458 11.2464L6.21558 4.83641L4.80505 5.34671ZM19.1168 10.8547L6.56378 18.2197L7.32284 19.5134L19.8758 12.1484L19.1168 10.8547ZM6.55627 18.2241C6.4893 18.2645 6.40506 18.2626 6.34 18.2192L5.50815 19.4674C6.05633 19.8327 6.76609 19.8489 7.33035 19.509L6.55627 18.2241ZM6.34 18.2192C6.27494 18.1759 6.24075 18.0988 6.25221 18.0215L4.76841 17.8016C4.67184 18.4532 4.95998 19.1021 5.50815 19.4674L6.34 18.2192ZM6.21558 18.1667L8.53458 11.7567L7.12405 11.2464L4.80505 17.6564L6.21558 18.1667ZM19.4963 10.7516H7.82931V12.2516H19.4963V10.7516Z" fill="currentColor"></path>
</svg>
"""
html = ""
md = MarkdownIt()
for i, (sender, msg) in reversed(list(enumerate(history))):
if sender == "user":
html += f'<div class="bubble user">{md.render(msg)}</div>'
else:
html += f'<div class="bubble bot">{md.render(msg)}'
# Add like/dislike buttons
val_like = likes[i] if i in likes else 0
# val_like = 0
# if i in likes:
# val_like = likes[i]
like = like_filled if val_like == 1 else like_empty
unlike = unlike_filled if val_like == -1 else unlike_empty
html += f"""
<div style="margin-top: 5px;">
<button onclick="feedback({i},1)" class="feedback-btn">
{like}
</button>
<button onclick="feedback({i},-1)" class="feedback-btn">
{unlike}
</button>
</div>
"""
# Add comment box
html += f"""
<div class="comment-box">
<input type="text" id="comment_input_{i}" placeholder="Add a comment..." style="width: 80%;">
<button onclick="submit_comment({i})">{send}</button>
</div>
"""
# Add others comments
if i in comments:
for comment in comments[i]:
html += f'<div class="comment">💬 {comment}</div>'
html += "</div>"
return f"""
<style>
svg {{
width: 18px;
height: 18px;
}}
.chat-container {{
font-family: sans-serif;
max-height: 70vh;
overflow-y: auto;
display: flex;
flex-direction: column-reverse;
}}
.bubble {{
max-width: 70%;
padding: 10px;
margin: 5px;
border-radius: 15px;
line-height: 1.4em;
}}
.user {{
background-color: #D1C0B2;
align-self: flex-end;
}}
.bot {{
background-color: #8FD7F7;
align-self: flex-start;
}}
.feedback-btn {{
font-size: 0.9em;
margin-right: 5px;
padding: 3px 8px;
cursor: pointer;
}}
.comment {{
font-size: 0.85em;
margin-left: 10px;
color: #555;
}}
.comment-box {{
margin-top: 5px;
}}
#comm, #like, #begin, #logoUB {{
visibility: hidden;
}}
div.svelte-633qhp{{
background: white !important;
border: none !important;
}}
</style>
<div class="chat-container">
{html}
</div>
"""
js="""
document.getElementById("like").style.visibility = "hidden";
document.getElementById("comm").style.visibility = "hidden";
"""
head="""
<style>
#hidden, #comm, #like {{
visibility: hidden;
}}
</style>
<script>
window.addEventListener('load', function () {
document.getElementById("hidden").style.visibility = "hidden";
document.getElementById("comm").style.visibility = "hidden";
document.getElementById("like").style.visibility = "hidden";
})
function feedback(nb_rep,val) {{
const divTxtBox = document.getElementById("like");
const txtBox = divTxtBox.getElementsByTagName("textarea")[0];
txtBox.value=nb_rep+" : "+val;
txtBox.dispatchEvent(new Event('input'));
}}
function submit_comment(nb_rep) {{
const divTxtBox = document.getElementById("comm");
const txtBox = divTxtBox.getElementsByTagName("textarea")[0];
const txtBoxInput = document.getElementById("comment_input_"+nb_rep);
txtBox.value=nb_rep+" : "+txtBoxInput.value;
txtBox.dispatchEvent(new Event('input'));
}}
</script>
"""
css= """
#hidden {{
visibility: hidden !important;
background: white !important;
}};
"""
# agent = gr.State(init_agent())
# txtBox.innerHTML='reply '+nb_rep+": "+val;
data = {}
def store_data(request: gr.Request, state, likes, comment_state):
data[request.session_hash] = {"state": state, "likes": likes, "comment_state": comment_state}
def save_and_clean_data(request: gr.Request):
# print(data[request.session_hash])
# global data
print(data)
if data[request.session_hash]['state']:
with open('log.json', 'a') as fp:
json.dump(data[request.session_hash], fp, ensure_ascii=False, indent=2)
fp.write(',\n')
data.pop(request.session_hash, None)
with gr.Blocks(head=head) as demo:
UB_logo = """
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="200" height="200" style="margin:auto" id="logoUB">
<path d="M0 0 C66 0 132 0 200 0 C200 66 200 132 200 200 C134 200 68 200 0 200 C0 134 0 68 0 0 Z " fill="#FEFEFD" transform="translate(0,0)"/>
<path d="M0 0 C1.49071976 -0.01646491 2.98136371 -0.04362866 4.47167969 -0.08203125 C20.53804283 -0.49375978 20.53804283 -0.49375978 26.69213867 5.35009766 C31.45138294 10.14957614 33.9779194 14.22418332 34.00463867 21.03759766 C33.97924208 25.22295555 33.51469082 28.22649243 31.81713867 32.03759766 C30.87929296 34.13906394 30.87929296 34.13906394 30.69213867 36.35009766 C31.89694441 39.02886786 33.35029669 41.10967463 35.17651367 43.40478516 C38.77424227 48.02248835 38.10160968 53.78873689 37.69213867 59.35009766 C36.36035779 66.09289379 33.70472576 71.53677817 27.95385742 75.56884766 C20.58576646 79.98654673 13.59232395 79.53634133 5.25561523 79.53540039 C3.06759483 79.5375972 0.88007065 79.55580322 -1.30786133 79.57470703 C-2.69588044 79.57763931 -4.08390194 79.57962521 -5.47192383 79.58056641 C-7.36612061 79.58672974 -7.36612061 79.58672974 -9.29858398 79.59301758 C-12.30786133 79.35009766 -12.30786133 79.35009766 -14.30786133 77.35009766 C-14.50078556 74.91626135 -14.57027154 72.5967541 -14.55078125 70.16235352 C-14.5526796 69.42239639 -14.55457794 68.68243927 -14.55653381 67.9200592 C-14.56024594 65.46824633 -14.54953222 63.01672806 -14.53833008 60.56494141 C-14.53713852 58.86625707 -14.53668506 57.16757207 -14.53694153 55.46888733 C-14.53537596 51.90703209 -14.52708008 48.34527725 -14.51367188 44.78344727 C-14.49666902 40.20764178 -14.49285785 35.63194661 -14.49361706 31.05611324 C-14.49334574 27.54837482 -14.48787087 24.04066073 -14.48061562 20.53293037 C-14.47742377 18.84515123 -14.47546034 17.15736932 -14.47472191 15.46958733 C-14.47256451 13.11582572 -14.4638338 10.76218343 -14.453125 8.40844727 C-14.45357819 7.7045285 -14.45403137 7.00060974 -14.45449829 6.27536011 C-14.39534835 -2.57233918 -7.19578625 0.05815094 0 0 Z " fill="#3B1F16" transform="translate(133.307861328125,86.64990234375)"/>
<path d="M0 0 C0.00142502 0.92184082 0.00285004 1.84368164 0.00431824 2.79345703 C0.02218635 11.5031741 0.06391275 20.21238549 0.13209057 28.92185974 C0.16630537 33.39898305 0.19146193 37.87576713 0.19555664 42.35302734 C0.19985149 46.67812991 0.22841161 51.00246794 0.27343178 55.32733154 C0.28636906 56.97299742 0.29072786 58.61875496 0.28615379 60.26446533 C0.03063751 72.59995224 0.03063751 72.59995224 6 83 C11.73610868 88.20251717 15.79156905 88.47284926 23.4375 88.40234375 C27.74405029 87.915968 30.04326007 86.78829497 33.3515625 84.09375 C39.92193256 75.74844584 39.60396014 67.58273208 39.609375 57.46875 C39.62437327 55.86590925 39.64110386 54.26308385 39.65948486 52.66027832 C39.70298627 48.46491749 39.72311897 44.26976509 39.73822021 40.07421875 C39.75785376 35.78372969 39.79981654 31.49346369 39.83984375 27.203125 C39.91495916 18.80214199 39.96536318 10.40124701 40 2 C42.47923801 1.97314905 44.9581884 1.95323453 47.4375 1.9375 C48.14455078 1.92912109 48.85160156 1.92074219 49.58007812 1.91210938 C51.38693559 1.90346412 53.19387603 1.94779989 55 2 C56.86005229 3.86005229 56.15699311 6.95508373 56.17700195 9.44067383 C56.18357315 10.11404785 56.19014435 10.78742187 56.19691467 11.48120117 C56.21671418 13.72314562 56.22833348 15.96502242 56.23828125 18.20703125 C56.24235678 18.9744483 56.2464323 19.74186535 56.25063133 20.53253746 C56.27153417 24.6052664 56.28580968 28.67796137 56.29516602 32.75073242 C56.30615562 36.93222752 56.34045523 41.11317936 56.38033772 45.29448414 C56.4066826 48.52816148 56.41487422 51.76171394 56.41844749 54.99548912 C56.42327853 56.53466083 56.4347914 58.0738283 56.45348549 59.61289406 C56.60047757 72.53239332 55.13547994 84.15668626 46 94 C45.49855469 94.54269531 44.99710937 95.08539063 44.48046875 95.64453125 C37.67696953 102.18317405 29.1577529 105.27797455 19.8125 105.5 C8.04937236 105.03310629 0.0700409 100.67201517 -8.1015625 92.28125 C-14.09220673 85.08261578 -16.13442807 77.41720621 -16.11352539 68.17822266 C-16.11344986 67.05751373 -16.11337433 65.93680481 -16.11329651 64.78213501 C-16.10813522 63.58817108 -16.10297394 62.39420715 -16.09765625 61.1640625 C-16.0962413 59.92957367 -16.09482635 58.69508484 -16.09336853 57.42318726 C-16.08778272 53.49043325 -16.07523275 49.55773672 -16.0625 45.625 C-16.05691912 42.95442792 -16.05292058 40.28385637 -16.04882812 37.61328125 C-16.03781792 31.07550131 -16.02109385 24.53775476 -16 18 C-16.75925781 17.79503906 -17.51851562 17.59007813 -18.30078125 17.37890625 C-19.29464844 17.10949219 -20.28851563 16.84007813 -21.3125 16.5625 C-22.29863281 16.29566406 -23.28476562 16.02882813 -24.30078125 15.75390625 C-26.21517526 15.21920575 -28.11433615 14.62855462 -30 14 C-30 12.02 -30 10.04 -30 8 C-26.31890319 6.64851224 -22.62922771 5.32214326 -18.9375 4 C-17.89916016 3.6184375 -16.86082031 3.236875 -15.79101562 2.84375 C-14.26831055 2.30234375 -14.26831055 2.30234375 -12.71484375 1.75 C-11.78792725 1.41484375 -10.86101074 1.0796875 -9.90600586 0.734375 C-6.52476734 -0.12009576 -3.47565393 -0.04807386 0 0 Z " fill="#3D2219" transform="translate(57,46)"/>
<path d="M0 0 C0 13.2 0 26.4 0 40 C-11 44 -11 44 -16 44 C-16 35.42 -16 26.84 -16 18 C-19.63 17.01 -23.26 16.02 -27 15 C-27.99 14.67 -28.98 14.34 -30 14 C-30 12.02 -30 10.04 -30 8 C-26.31890319 6.64851224 -22.62922771 5.32214326 -18.9375 4 C-17.89916016 3.6184375 -16.86082031 3.236875 -15.79101562 2.84375 C-14.26831055 2.30234375 -14.26831055 2.30234375 -12.71484375 1.75 C-11.78792725 1.41484375 -10.86101074 1.0796875 -9.90600586 0.734375 C-7 0 -7 0 0 0 Z " fill="#019CDF" transform="translate(57,46)"/>
<path d="M0 0 C15.26785714 -0.66964286 15.26785714 -0.66964286 18.9375 1.875 C21.42152538 5.63867481 21.67847666 8.0750205 21.69921875 12.5 C20.6572313 16.22554173 19.09311786 17.70654647 16 20 C13.18750055 20.57882195 10.54299078 20.4770774 7.6875 20.3125 C5.150625 20.209375 2.61375 20.10625 0 20 C0 13.4 0 6.8 0 0 Z " fill="#F6F3F1" transform="translate(134,131)"/>
<path d="M0 0 C0 13.2 0 26.4 0 40 C-11 44 -11 44 -16 44 C-16 35.42 -16 26.84 -16 18 C-19.63 17.01 -23.26 16.02 -27 15 C-27.99 14.67 -28.98 14.34 -30 14 C-30 12.02 -30 10.04 -30 8 C-26.31890319 6.64851224 -22.62922771 5.32214326 -18.9375 4 C-17.89916016 3.6184375 -16.86082031 3.236875 -15.79101562 2.84375 C-14.26831055 2.30234375 -14.26831055 2.30234375 -12.71484375 1.75 C-11.78792725 1.41484375 -10.86101074 1.0796875 -9.90600586 0.734375 C-7 0 -7 0 0 0 Z M-16.1875 4.375 C-17.97220703 5.03628906 -17.97220703 5.03628906 -19.79296875 5.7109375 C-22.27590311 6.70895009 -24.63986437 7.74672699 -27 9 C-27 10.32 -27 11.64 -27 13 C-25.82630859 13.29003906 -25.82630859 13.29003906 -24.62890625 13.5859375 C-23.61699219 13.84632812 -22.60507812 14.10671875 -21.5625 14.375 C-20.55316406 14.63023438 -19.54382813 14.88546875 -18.50390625 15.1484375 C-16 16 -16 16 -15 18 C-14.84693099 19.81171098 -14.75053339 21.6283794 -14.68359375 23.4453125 C-14.62075195 25.05986328 -14.62075195 25.05986328 -14.55664062 26.70703125 C-14.51732422 27.83496094 -14.47800781 28.96289062 -14.4375 30.125 C-14.39431641 31.26066406 -14.35113281 32.39632812 -14.30664062 33.56640625 C-14.2003396 36.37747768 -14.09830595 39.18863945 -14 42 C-10.535 41.505 -10.535 41.505 -7 41 C-7 40.34 -7 39.68 -7 39 C-5.35 39 -3.7 39 -2 39 C-2 26.79 -2 14.58 -2 2 C-8.04155958 2 -10.80257737 2.34317532 -16.1875 4.375 Z " fill="#2F9BCA" transform="translate(57,46)"/>
<path d="M0 0 C13.32478304 -0.49351048 13.32478304 -0.49351048 16.453125 1.79296875 C18 4 18 4 18 7.5625 C16.87768796 11.42044765 16.42667139 12.1164654 13 14 C9.765625 14.29296875 9.765625 14.29296875 6.25 14.1875 C4.1875 14.125625 2.125 14.06375 0 14 C0 9.38 0 4.76 0 0 Z " fill="#FAF7F5" transform="translate(134,102)"/>
<path d="M0 0 C-1.76755526 0.84026396 -3.53917263 1.67198722 -5.3125 2.5 C-6.29863281 2.9640625 -7.28476562 3.428125 -8.30078125 3.90625 C-11 5 -11 5 -14 5 C-14 6.32 -14 7.64 -14 9 C-13.21753906 9.13277344 -12.43507813 9.26554687 -11.62890625 9.40234375 C-10.11103516 9.66724609 -10.11103516 9.66724609 -8.5625 9.9375 C-7.55316406 10.11152344 -6.54382813 10.28554688 -5.50390625 10.46484375 C-3 11 -3 11 -2 12 C-1.91241997 13.99964982 -1.89303424 16.0023611 -1.90234375 18.00390625 C-1.90556641 19.21884766 -1.90878906 20.43378906 -1.91210938 21.68554688 C-1.92048828 22.96494141 -1.92886719 24.24433594 -1.9375 25.5625 C-1.94201172 26.84576172 -1.94652344 28.12902344 -1.95117188 29.45117188 C-1.96300455 32.63416022 -1.97948932 35.81705762 -2 39 C-2.33 39 -2.66 39 -3 39 C-3 30.75 -3 22.5 -3 14 C-6.63 13.01 -10.26 12.02 -14 11 C-14.99 10.67 -15.98 10.34 -17 10 C-17 8.02 -17 6.04 -17 4 C-14.54453034 3.13670227 -12.08621957 2.28410564 -9.625 1.4375 C-8.57699219 1.0672168 -8.57699219 1.0672168 -7.5078125 0.68945312 C-2.2265625 -1.11328125 -2.2265625 -1.11328125 0 0 Z " fill="#3EA4D1" transform="translate(44,50)"/>
<path d="M0 0 C2.05078125 0.03255208 4.1015625 0.06510417 6.15234375 0.09765625 C6.15234375 0.42765625 6.15234375 0.75765625 6.15234375 1.09765625 C5.22421875 1.36578125 4.29609375 1.63390625 3.33984375 1.91015625 C0.38994009 3.00913996 -0.90380811 3.72184186 -2.84765625 6.09765625 C-2.89037725 4.4315372 -2.88829457 2.7638274 -2.84765625 1.09765625 C-1.84765625 0.09765625 -1.84765625 0.09765625 0 0 Z " fill="#433029" transform="translate(121.84765625,86.90234375)"/>
</svg>
"""
gr.HTML("""
<style>
#hidden, #comm, #like{
visibility: hidden;
}
</style>
""")
gr.HTML(f"<h1 style='text-align: center;'>{UB_logo} Chatbot UBX</h1>")
gr.HTML("""<p style='text-align: center;'>
Ce chatbot répond à des questions administratives de l'Université de Bordeaux.<br>
Les réponses seront enregistrées dans le cadre d'une étude d'amélioration de cet outil.</p>""")
gr.HTML("<h2 id='begin' style='text-align: center;'><strong>Commencez une discussion</h2>")
# with gr.Row():
# with gr.Row(scale=9):
chat_output = gr.HTML()
user_input = gr.Textbox(placeholder="Ecrivez votre question ici ...", show_label=False)
state = gr.State([])
likes = gr.State({})
comment_state = gr.State({})
demo.load(store_data, [state, likes, comment_state], None)
demo.unload(save_and_clean_data)
agent = gr.State(init_agent())
user_input.submit(respond, [agent, user_input, state, comment_state, likes], [agent, user_input, chat_output, state, comment_state])
# Hidden component to receive JS feedback via endpoint
with gr.Row(scale=0,elem_id="hidden"):
feedback_input = gr.Textbox(elem_id='like')
feedback_input.change(handle_feedback, [state, comment_state, feedback_input, likes], [chat_output, feedback_input, likes])
comment_text = gr.Textbox(elem_id='comm')
comment_text.change(add_comment, [comment_text, comment_state, state, likes], [chat_output, comment_state], show_progress=False)
if __name__ == "__main__":
demo.launch(share=True)