Spaces:
Sleeping
Sleeping
LucasAguetai
commited on
Commit
·
1d71dd5
1
Parent(s):
505edcf
add limit caracter
Browse files
app.py
CHANGED
@@ -35,8 +35,7 @@ if "messages" not in st.session_state:
|
|
35 |
if prompt := st.chat_input(placeholder="Write to ALOQAS..."):
|
36 |
st.session_state.messages.append({"role": "user", "content": prompt})
|
37 |
params = {'texte': prompt, "model": model}
|
38 |
-
|
39 |
-
if userContext is not '':
|
40 |
if contextSelect == "File" and userContext:
|
41 |
# Préparation de la liste des fichiers pour l'envoi
|
42 |
files = [("file", (file.name, file, file.type)) for file in userContext]
|
@@ -46,15 +45,18 @@ if prompt := st.chat_input(placeholder="Write to ALOQAS..."):
|
|
46 |
request_url = f"{siteUrl}/{model.lower()}/?context={userContext}&question={prompt}"
|
47 |
response = requests.post(request_url)
|
48 |
print(response.text)
|
|
|
49 |
st.session_state.messages.append({"role": "assistant", "content": json.loads(response.text)["answer"]})
|
50 |
|
51 |
-
|
52 |
error = 1
|
|
|
|
|
53 |
|
54 |
# st.write("Statut de la requête:", response.status_code)
|
55 |
# st.write("Réponse du serveur:", response.text)
|
56 |
|
57 |
-
if userContext
|
58 |
with st.sidebar:
|
59 |
st.title("Statistics on the last answer")
|
60 |
st.write(f"Score: {round(json.loads(response.text)['score'], 3)}")
|
@@ -65,6 +67,10 @@ for msg in st.session_state.messages:
|
|
65 |
st.chat_message(msg["role"]).write(msg['content'])
|
66 |
|
67 |
if error == 1:
|
68 |
-
|
69 |
-
|
70 |
-
|
|
|
|
|
|
|
|
|
|
35 |
if prompt := st.chat_input(placeholder="Write to ALOQAS..."):
|
36 |
st.session_state.messages.append({"role": "user", "content": prompt})
|
37 |
params = {'texte': prompt, "model": model}
|
38 |
+
if userContext != '' and len(userContext) <= 9000:
|
|
|
39 |
if contextSelect == "File" and userContext:
|
40 |
# Préparation de la liste des fichiers pour l'envoi
|
41 |
files = [("file", (file.name, file, file.type)) for file in userContext]
|
|
|
45 |
request_url = f"{siteUrl}/{model.lower()}/?context={userContext}&question={prompt}"
|
46 |
response = requests.post(request_url)
|
47 |
print(response.text)
|
48 |
+
print(response)
|
49 |
st.session_state.messages.append({"role": "assistant", "content": json.loads(response.text)["answer"]})
|
50 |
|
51 |
+
elif userContext == '' :
|
52 |
error = 1
|
53 |
+
else :
|
54 |
+
error = 2
|
55 |
|
56 |
# st.write("Statut de la requête:", response.status_code)
|
57 |
# st.write("Réponse du serveur:", response.text)
|
58 |
|
59 |
+
if userContext != '' and len(userContext) <= 9000:
|
60 |
with st.sidebar:
|
61 |
st.title("Statistics on the last answer")
|
62 |
st.write(f"Score: {round(json.loads(response.text)['score'], 3)}")
|
|
|
67 |
st.chat_message(msg["role"]).write(msg['content'])
|
68 |
|
69 |
if error == 1:
|
70 |
+
message_rouge = "⚠️ Please provide a context via the menu on your left."
|
71 |
+
st.markdown(f'<div style="color: white; background-color: #ff4444; padding: 10px; border-radius: 5px;">{message_rouge}</div>', unsafe_allow_html=True)
|
72 |
+
error = 0
|
73 |
+
elif error == 2:
|
74 |
+
message_rouge = "⚠️ Please provide a context less than 9000 caractere."
|
75 |
+
st.markdown(f'<div style="color: white; background-color: #ff4444; padding: 10px; border-radius: 5px;">{message_rouge}</div>', unsafe_allow_html=True)
|
76 |
+
error = 0
|