Spaces:
Sleeping
Sleeping
Samuel-DD07
commited on
Commit
•
30b0fcd
1
Parent(s):
375bf89
Mise à jour de l'interface utilisateur et des messages d'accueil
Browse files
app.py
CHANGED
@@ -13,20 +13,35 @@ limit = 9000
|
|
13 |
with st.sidebar:
|
14 |
st.title("Configuration")
|
15 |
model = st.selectbox('Which model would you like to use?',
|
16 |
-
('SqueezeBERT', 'BERT', 'DeBERTa'))
|
17 |
-
contextSelect = st.radio("Pick a context mode:", ["Text", "File"])
|
18 |
if contextSelect == "File":
|
19 |
userContext = st.file_uploader("Pick a file for the context", accept_multiple_files=True)
|
20 |
context = "/uploadfile/"
|
21 |
else:
|
22 |
-
userContext = st.text_area("Write the context")
|
23 |
context = "/contextText/"
|
24 |
|
25 |
st.title("ALOQAS")
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
if "messages" not in st.session_state:
|
32 |
st.session_state["messages"] = [
|
@@ -40,7 +55,6 @@ if prompt := st.chat_input(placeholder="Write to ALOQAS..."):
|
|
40 |
|
41 |
if userContext != '' and len(userContext) <= limit:
|
42 |
if contextSelect == "File" and userContext:
|
43 |
-
# Préparation de la liste des fichiers pour l'envoi
|
44 |
files = [("files", (file.name, file, file.type)) for file in userContext]
|
45 |
response = requests.post(siteUrl + context, data=params, files=files)
|
46 |
st.session_state.messages.append({"role": "assistant", "content": json.loads(response.text).get("answer", "Sorry, I couldn't find an answer for your question.")})
|
@@ -49,18 +63,11 @@ if prompt := st.chat_input(placeholder="Write to ALOQAS..."):
|
|
49 |
response = requests.post(siteUrl + context, json=params)
|
50 |
st.session_state.messages.append({"role": "assistant", "content": json.loads(response.text).get("answer", "Sorry, I couldn't find an answer for your question.")})
|
51 |
|
52 |
-
|
53 |
-
# # st.write("Statut de la requête:", response.status_code)
|
54 |
-
# # st.write("Réponse du serveur:", response.text)
|
55 |
-
|
56 |
if response is None:
|
57 |
error = 3
|
58 |
if userContext != '' and len(userContext) <= limit and response is not None:
|
59 |
with st.sidebar:
|
60 |
-
st.
|
61 |
-
st.write(f"Score: {round(json.loads(response.text).get('score', 0), 2)}")
|
62 |
-
st.write(f"Start: {json.loads(response.text).get('start', 0)}")
|
63 |
-
st.write(f"End: {json.loads(response.text).get('end', 0)}")
|
64 |
|
65 |
elif userContext == '' :
|
66 |
error = 1
|
@@ -77,12 +84,12 @@ if error == 1:
|
|
77 |
st.markdown(f'<div style="color: white; background-color: #ff4444; padding: 10px; border-radius: 5px;">{message_rouge}</div>', unsafe_allow_html=True)
|
78 |
error = 0
|
79 |
elif error == 2:
|
80 |
-
message_rouge = f"⚠️ The message you submitted was too long, please reload the conversation and submit something shorter than {limit}
|
81 |
st.markdown(f'<div style="color: white; background-color: #ff4444; padding: 10px; border-radius: 5px;">{message_rouge}</div>', unsafe_allow_html=True)
|
82 |
error = 0
|
83 |
elif error == 3:
|
84 |
-
message_rouge = f"⚠️ An error
|
85 |
st.markdown(f'<div style="color: white; background-color: #ff4444; padding: 10px; border-radius: 5px;">{message_rouge}</div>', unsafe_allow_html=True)
|
86 |
error = 0
|
87 |
else:
|
88 |
-
st.write("")
|
|
|
13 |
with st.sidebar:
|
14 |
st.title("Configuration")
|
15 |
model = st.selectbox('Which model would you like to use?',
|
16 |
+
('SqueezeBERT', 'BERT', 'DeBERTa'), index=1, help="SqueezeBERT is faster but less accurate, BERT is balanced, and DeBERTa is slower but more accurate.")
|
17 |
+
contextSelect = st.radio("Pick a context mode:", ["Text", "File"], index=0, help="Choose between text or file context.")
|
18 |
if contextSelect == "File":
|
19 |
userContext = st.file_uploader("Pick a file for the context", accept_multiple_files=True)
|
20 |
context = "/uploadfile/"
|
21 |
else:
|
22 |
+
userContext = st.text_area("Write the context", max_chars=limit, help="Insert the context text here.")
|
23 |
context = "/contextText/"
|
24 |
|
25 |
st.title("ALOQAS")
|
26 |
|
27 |
+
# Dynamic welcome message based on model and context selection
|
28 |
+
if model and contextSelect:
|
29 |
+
if model == 'DeBERTa':
|
30 |
+
model_info = "Using the DeBERTa model for the most accurate answers, although it may be slower."
|
31 |
+
elif model == 'SqueezeBERT':
|
32 |
+
model_info = "Using the SqueezeBERT model for faster but less precise answers."
|
33 |
+
else:
|
34 |
+
model_info = "Using the BERT model as a balance between speed and accuracy."
|
35 |
+
|
36 |
+
if contextSelect == "File":
|
37 |
+
context_info = "Upload files of types: txt, json, docx, pdf, csv for context."
|
38 |
+
else:
|
39 |
+
context_info = f"Insert text context up to {limit} characters."
|
40 |
+
|
41 |
+
st.subheader("Welcome to ALOQAS AI")
|
42 |
+
st.write(f"{model_info} {context_info}")
|
43 |
+
st.write("")
|
44 |
+
st.write("")
|
45 |
|
46 |
if "messages" not in st.session_state:
|
47 |
st.session_state["messages"] = [
|
|
|
55 |
|
56 |
if userContext != '' and len(userContext) <= limit:
|
57 |
if contextSelect == "File" and userContext:
|
|
|
58 |
files = [("files", (file.name, file, file.type)) for file in userContext]
|
59 |
response = requests.post(siteUrl + context, data=params, files=files)
|
60 |
st.session_state.messages.append({"role": "assistant", "content": json.loads(response.text).get("answer", "Sorry, I couldn't find an answer for your question.")})
|
|
|
63 |
response = requests.post(siteUrl + context, json=params)
|
64 |
st.session_state.messages.append({"role": "assistant", "content": json.loads(response.text).get("answer", "Sorry, I couldn't find an answer for your question.")})
|
65 |
|
|
|
|
|
|
|
|
|
66 |
if response is None:
|
67 |
error = 3
|
68 |
if userContext != '' and len(userContext) <= limit and response is not None:
|
69 |
with st.sidebar:
|
70 |
+
st.markdown(f"<div style='color: white; background-color: #0F1116 ; padding: 10px; border-radius: 5px;'><h2 style='color: white;'>Statistics on the last answer</h2><p>Time: {json.loads(str(round(response.elapsed.total_seconds(), 2)))}s</p><p>Score: {round(json.loads(response.text).get('score', 0), 2)}</p><p>Start: {json.loads(response.text).get('start', 0)}</p><p>End: {json.loads(response.text).get('end', 0)}</p></div>", unsafe_allow_html=True)
|
|
|
|
|
|
|
71 |
|
72 |
elif userContext == '' :
|
73 |
error = 1
|
|
|
84 |
st.markdown(f'<div style="color: white; background-color: #ff4444; padding: 10px; border-radius: 5px;">{message_rouge}</div>', unsafe_allow_html=True)
|
85 |
error = 0
|
86 |
elif error == 2:
|
87 |
+
message_rouge = f"⚠️ The message you submitted was too long, please reload the conversation and submit something shorter than {limit} characters."
|
88 |
st.markdown(f'<div style="color: white; background-color: #ff4444; padding: 10px; border-radius: 5px;">{message_rouge}</div>', unsafe_allow_html=True)
|
89 |
error = 0
|
90 |
elif error == 3:
|
91 |
+
message_rouge = f"⚠️ An error occurred, please try again."
|
92 |
st.markdown(f'<div style="color: white; background-color: #ff4444; padding: 10px; border-radius: 5px;">{message_rouge}</div>', unsafe_allow_html=True)
|
93 |
error = 0
|
94 |
else:
|
95 |
+
st.write("")
|