Spaces:
Sleeping
Sleeping
Samuel-DD07
commited on
Commit
·
d9e6c85
1
Parent(s):
30b0fcd
Définir les configurations et les variables initiales, configurer la barre latérale avec une sélection de modèle et un groupe de boutons radio pour la sélection du mode de contexte, ajouter un titre principal à la page principale, afficher un message de bienvenue dynamique basé sur la sélection du modèle et du contexte, et afficher un message d'erreur si aucun contexte n'est fourni.
Browse files
app.py
CHANGED
@@ -2,26 +2,38 @@ 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
|
11 |
limit = 9000
|
|
|
|
|
12 |
|
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
|
|
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
|
@@ -79,6 +91,7 @@ if prompt := st.chat_input(placeholder="Write to ALOQAS..."):
|
|
79 |
for msg in st.session_state.messages:
|
80 |
st.chat_message(msg.get("role", "assistant")).write(msg.get("content", "Hi, I'm ALOQAS. How can I help you?"))
|
81 |
|
|
|
82 |
if error == 1:
|
83 |
message_rouge = "⚠️ Please provide a context via the menu on your left."
|
84 |
st.markdown(f'<div style="color: white; background-color: #ff4444; padding: 10px; border-radius: 5px;">{message_rouge}</div>', unsafe_allow_html=True)
|
|
|
2 |
import requests
|
3 |
import json
|
4 |
|
5 |
+
# Define initial configurations and variables
|
6 |
siteUrl = "https://aloqas-aloqas-qa-fastapi.hf.space"
|
|
|
7 |
response = None
|
8 |
userContext = None
|
9 |
context = None
|
10 |
error = 0
|
11 |
limit = 9000
|
12 |
+
model = None
|
13 |
+
|
14 |
|
15 |
+
def on_change_write_name_of_model():
|
16 |
+
selected_model = st.session_state['model']
|
17 |
+
st.session_state.messages.append({"role": "assistant", "content": f"Switched to {selected_model} model."})
|
18 |
+
|
19 |
+
# Sidebar configuration
|
20 |
with st.sidebar:
|
21 |
st.title("Configuration")
|
22 |
+
# Define a selectbox for model selection
|
23 |
model = st.selectbox('Which model would you like to use?',
|
24 |
+
('SqueezeBERT', 'BERT', 'DeBERTa'), index=1,
|
25 |
+
help="SqueezeBERT is faster but less accurate, BERT is balanced, and DeBERTa is slower but more accurate.",
|
26 |
+
on_change=on_change_write_name_of_model, key='model')
|
27 |
+
# Define a radio button group for context mode selection
|
28 |
contextSelect = st.radio("Pick a context mode:", ["Text", "File"], index=0, help="Choose between text or file context.")
|
29 |
if contextSelect == "File":
|
30 |
+
userContext = st.file_uploader("Pick a file for the context", accept_multiple_files=True, help="Upload files of types: txt, json, docx, pdf, csv for context.", type=['txt', 'json', 'docx', 'pdf', 'csv'])
|
31 |
context = "/uploadfile/"
|
32 |
else:
|
33 |
userContext = st.text_area("Write the context", max_chars=limit, help="Insert the context text here.")
|
34 |
context = "/contextText/"
|
35 |
|
36 |
+
# Main page title
|
37 |
st.title("ALOQAS")
|
38 |
|
39 |
# Dynamic welcome message based on model and context selection
|
|
|
91 |
for msg in st.session_state.messages:
|
92 |
st.chat_message(msg.get("role", "assistant")).write(msg.get("content", "Hi, I'm ALOQAS. How can I help you?"))
|
93 |
|
94 |
+
|
95 |
if error == 1:
|
96 |
message_rouge = "⚠️ Please provide a context via the menu on your left."
|
97 |
st.markdown(f'<div style="color: white; background-color: #ff4444; padding: 10px; border-radius: 5px;">{message_rouge}</div>', unsafe_allow_html=True)
|