Spaces:
Sleeping
Sleeping
Samuel-DD07
commited on
Commit
•
375bf89
1
Parent(s):
7b7b42e
Mise à jour de l'interface utilisateur et des requêtes ALOQAS
Browse files
app.py
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
import streamlit as st
|
2 |
import requests
|
3 |
-
import streamlit as st
|
4 |
import json
|
5 |
|
6 |
siteUrl = "https://aloqas-aloqas-qa-fastapi.hf.space"
|
7 |
|
|
|
8 |
userContext = None
|
9 |
context = None
|
10 |
error = 0
|
@@ -13,13 +13,13 @@ 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("
|
23 |
context = "/contextText/"
|
24 |
|
25 |
st.title("ALOQAS")
|
@@ -35,37 +35,42 @@ if "messages" not in st.session_state:
|
|
35 |
|
36 |
if prompt := st.chat_input(placeholder="Write to ALOQAS..."):
|
37 |
st.session_state.messages.append({"role": "user", "content": prompt})
|
38 |
-
|
|
|
|
|
39 |
if userContext != '' and len(userContext) <= limit:
|
40 |
if contextSelect == "File" and userContext:
|
41 |
# Préparation de la liste des fichiers pour l'envoi
|
42 |
-
files = [("
|
43 |
-
response = requests.post(siteUrl + context,
|
|
|
44 |
else:
|
45 |
params["context"] = userContext
|
46 |
-
|
47 |
-
|
48 |
-
print(response.text)
|
49 |
-
print(response)
|
50 |
-
st.session_state.messages.append({"role": "assistant", "content": json.loads(response.text)["answer"]})
|
51 |
|
52 |
-
elif userContext == '' :
|
53 |
-
error = 1
|
54 |
-
else :
|
55 |
-
error = 2
|
56 |
|
57 |
-
|
58 |
-
|
59 |
|
60 |
-
if
|
|
|
|
|
61 |
with st.sidebar:
|
62 |
st.title("Statistics on the last answer")
|
63 |
-
st.write(f"Score: {round(json.loads(response.text)
|
64 |
-
st.write(f"Start: {json.loads(response.text)
|
65 |
-
st.write(f"End: {json.loads(response.text)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
|
67 |
for msg in st.session_state.messages:
|
68 |
-
st.chat_message(msg
|
69 |
|
70 |
if error == 1:
|
71 |
message_rouge = "⚠️ Please provide a context via the menu on your left."
|
@@ -75,3 +80,9 @@ elif error == 2:
|
|
75 |
message_rouge = f"⚠️ The message you submitted was too long, please reload the conversation and submit something shorter than {limit} caracter."
|
76 |
st.markdown(f'<div style="color: white; background-color: #ff4444; padding: 10px; border-radius: 5px;">{message_rouge}</div>', unsafe_allow_html=True)
|
77 |
error = 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
import requests
|
|
|
3 |
import json
|
4 |
|
5 |
siteUrl = "https://aloqas-aloqas-qa-fastapi.hf.space"
|
6 |
|
7 |
+
response = None
|
8 |
userContext = None
|
9 |
context = None
|
10 |
error = 0
|
|
|
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")
|
|
|
35 |
|
36 |
if prompt := st.chat_input(placeholder="Write to ALOQAS..."):
|
37 |
st.session_state.messages.append({"role": "user", "content": prompt})
|
38 |
+
|
39 |
+
params = {'question': prompt, "model": model.lower()}
|
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.")})
|
47 |
else:
|
48 |
params["context"] = userContext
|
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.title("Statistics on the last answer")
|
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
|
67 |
+
elif len(userContext) > limit:
|
68 |
+
error = 2
|
69 |
+
else:
|
70 |
+
error = 3
|
71 |
|
72 |
for msg in st.session_state.messages:
|
73 |
+
st.chat_message(msg.get("role", "assistant")).write(msg.get("content", "Hi, I'm ALOQAS. How can I help you?"))
|
74 |
|
75 |
if error == 1:
|
76 |
message_rouge = "⚠️ Please provide a context via the menu on your left."
|
|
|
80 |
message_rouge = f"⚠️ The message you submitted was too long, please reload the conversation and submit something shorter than {limit} caracter."
|
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 occured, please try again."
|
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("")
|