Commit
•
c9b1bae
0
Parent(s):
Synchronisation Frontend DracolIA QA
Browse files- Exceptions/FileTypeIsNotAcceptedException.py +2 -0
- README.md +10 -0
- Ressources/Config.py +3 -0
- Ressources/Session.py +57 -0
- Ressources/Translations.py +52 -0
- Services/Service_File.py +106 -0
- Services/__init__.py +0 -0
- Views/chatbot.py +219 -0
- Views/login.py +64 -0
- Views/signup.py +57 -0
- app.py +22 -0
- requirements.txt +8 -0
Exceptions/FileTypeIsNotAcceptedException.py
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
class FileTypeIsNotAcceptedException(Exception):
|
2 |
+
pass
|
README.md
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: SAE Question Answering IA Front
|
3 |
+
emoji: 😻
|
4 |
+
colorFrom: purple
|
5 |
+
colorTo: blue
|
6 |
+
sdk: streamlit
|
7 |
+
sdk_version: 1.32.2
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
---
|
Ressources/Config.py
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
URL = "https://dracolia-sae-question-answering-ia-back.hf.space/" # PROD URL
|
2 |
+
#URL = "http://localhost:5000/" # DEV URL
|
3 |
+
|
Ressources/Session.py
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
def initialize_session():
|
4 |
+
# APP
|
5 |
+
if 'current_page' not in st.session_state:
|
6 |
+
st.session_state['current_page'] = 'Login'
|
7 |
+
|
8 |
+
|
9 |
+
# LOGIN
|
10 |
+
if 'login_pressed' in st.session_state:
|
11 |
+
st.session_state['login_pressed'] = False
|
12 |
+
|
13 |
+
if 'user_id' not in st.session_state:
|
14 |
+
st.session_state['user_id'] = None
|
15 |
+
|
16 |
+
if 'user_name' not in st.session_state:
|
17 |
+
st.session_state['user_id'] = None
|
18 |
+
|
19 |
+
if 'user_is_connected' not in st.session_state:
|
20 |
+
st.session_state['user_is_connected'] = False
|
21 |
+
|
22 |
+
|
23 |
+
# SIGNUP
|
24 |
+
if 'signup_pressed' in st.session_state:
|
25 |
+
st.session_state['signup_pressed'] = False
|
26 |
+
|
27 |
+
|
28 |
+
# CHAT
|
29 |
+
if 'chat_history' not in st.session_state:
|
30 |
+
st.session_state['chat_history'] = {}
|
31 |
+
|
32 |
+
if 'selected_chat' not in st.session_state:
|
33 |
+
st.session_state['selected_chat'] = {}
|
34 |
+
|
35 |
+
if 'user_question' not in st.session_state:
|
36 |
+
st.session_state['user_question'] = ''
|
37 |
+
|
38 |
+
if 'chat_id' not in st.session_state:
|
39 |
+
st.session_state['chat_id'] = None
|
40 |
+
|
41 |
+
if 'file_content' not in st.session_state:
|
42 |
+
st.session_state['file_content'] = ''
|
43 |
+
|
44 |
+
if 'have_file' not in st.session_state:
|
45 |
+
st.session_state['have_file'] = False
|
46 |
+
|
47 |
+
if 'model_selected' not in st.session_state:
|
48 |
+
st.session_state['model_selected'] = "Bert"
|
49 |
+
|
50 |
+
if 'model_selected_bln' not in st.session_state:
|
51 |
+
st.session_state['model_selected_bln'] = False
|
52 |
+
|
53 |
+
if 'languages' not in st.session_state:
|
54 |
+
st.session_state['languages'] = "en"
|
55 |
+
|
56 |
+
if 'is_chat_show' not in st.session_state:
|
57 |
+
st.session_state['is_chat_show'] = False
|
Ressources/Translations.py
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
translations = {
|
2 |
+
"en": {
|
3 |
+
"language": "Language",
|
4 |
+
"username": "Username",
|
5 |
+
"password": "Password",
|
6 |
+
"home": "Home",
|
7 |
+
"signupPage":{
|
8 |
+
"signup": "Sign Up",
|
9 |
+
"description": "You don't have an account yet? Please signup. If you already have an account, please login.",
|
10 |
+
"connectAccount": "Connect to your account",
|
11 |
+
},
|
12 |
+
"loginPage":{
|
13 |
+
"login": "Login",
|
14 |
+
"description": "Welcome ! Please login to continue. If you don't have an account, please signup.",
|
15 |
+
"createAccount": "Create an account",
|
16 |
+
},
|
17 |
+
"chatbotPage":{
|
18 |
+
"selectModel":"Please select a model",
|
19 |
+
"chooseModel":"Choose the model you want to use.",
|
20 |
+
"selectedModel":"Selected model",
|
21 |
+
"changeModel":"Change model",
|
22 |
+
"enterQuestion":"Enter your question",
|
23 |
+
},
|
24 |
+
"generalError": "An error occurred. Please try again later. ",
|
25 |
+
"logout": "Logout"
|
26 |
+
},
|
27 |
+
"fr": {
|
28 |
+
"language": "Langue",
|
29 |
+
"username": "Nom d'utilisateur",
|
30 |
+
"password": "Mot de passe",
|
31 |
+
"home": "Accueil",
|
32 |
+
"signupPage": {
|
33 |
+
"signup": "S'inscrire",
|
34 |
+
"description": "Vous n'avez pas encore de compte ? Veuillez vous inscrire. Si vous avez déjà un compte, veuillez vous connecter.",
|
35 |
+
"connectAccount": "Connectez-vous"
|
36 |
+
},
|
37 |
+
"loginPage": {
|
38 |
+
"login": "Connexion",
|
39 |
+
"description": "Bienvenue ! Veuillez vous connecter pour continuer. Si vous n'avez pas de compte, veuillez vous inscrire.",
|
40 |
+
"createAccount": "Créer un compte"
|
41 |
+
},
|
42 |
+
"chatbotPage": {
|
43 |
+
"selectModel": "Veuillez sélectionner un modèle",
|
44 |
+
"chooseModel": "Choisissez le modèle que vous souhaitez utiliser.",
|
45 |
+
"selectedModel": "Modèle sélectionné",
|
46 |
+
"changeModel": "Changer de modèle",
|
47 |
+
"enterQuestion": "Entrez votre question"
|
48 |
+
},
|
49 |
+
"generalError": "Une erreur s'est produite. Veuillez réessayer plus tard. ",
|
50 |
+
"logout": "Déconnexion"
|
51 |
+
}
|
52 |
+
}
|
Services/Service_File.py
ADDED
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import fitz
|
2 |
+
from docx import Document
|
3 |
+
from reportlab.pdfgen import canvas
|
4 |
+
from reportlab.lib.pagesizes import letter
|
5 |
+
import pandas as pd
|
6 |
+
from Exceptions.FileTypeIsNotAcceptedException import FileTypeIsNotAcceptedException
|
7 |
+
from googletrans import Translator
|
8 |
+
import PyPDF2
|
9 |
+
from io import BytesIO
|
10 |
+
|
11 |
+
class Service_File:
|
12 |
+
def __init__(self):
|
13 |
+
pass
|
14 |
+
|
15 |
+
def file_for_string(self, file):
|
16 |
+
translator = Translator()
|
17 |
+
|
18 |
+
if file.name.endswith('.docx'):
|
19 |
+
print("File is a docx")
|
20 |
+
string = self.word_to_string(file)
|
21 |
+
|
22 |
+
elif file.name.endswith('.pdf'):
|
23 |
+
print("File is a pdf")
|
24 |
+
string = self.pdf_to_string(file)
|
25 |
+
|
26 |
+
elif file.name.endswith('.xlsx'):
|
27 |
+
print("File is an .xlsx")
|
28 |
+
string = self.excel_to_string(file)
|
29 |
+
|
30 |
+
elif file.name.endswith('.csv'):
|
31 |
+
print("File is a .csv")
|
32 |
+
string = self.csv_to_string(file)
|
33 |
+
|
34 |
+
else:
|
35 |
+
raise FileTypeIsNotAcceptedException('File type is not accepted. Please upload a .docx, .pdf, .xlsx or .csv file.')
|
36 |
+
|
37 |
+
string = string.replace('\n', ' ').replace('\t', ' ').replace('"', ' ').replace("'", ' ')
|
38 |
+
split = self.split_text(string)
|
39 |
+
print(len(split))
|
40 |
+
|
41 |
+
translate = ""
|
42 |
+
for i in range(len(split)):
|
43 |
+
print(i)
|
44 |
+
language = translator.detect(str(split[i])).lang.upper() # Verify the language of the prompt
|
45 |
+
if split[i] != "" or len(split[i]) != 0:
|
46 |
+
if language != "EN":
|
47 |
+
translate = translate + translator.translate(str(split[i]), src=language, dest="EN").text
|
48 |
+
else:
|
49 |
+
translate = translate + split[i]
|
50 |
+
|
51 |
+
print("translate: ", translate)
|
52 |
+
return translate
|
53 |
+
|
54 |
+
|
55 |
+
def split_text(self, text, max_chars=1500):
|
56 |
+
if len(text) <= max_chars:
|
57 |
+
return [text]
|
58 |
+
|
59 |
+
split_texts = []
|
60 |
+
current_text = ""
|
61 |
+
words = text.split()
|
62 |
+
for word in words:
|
63 |
+
if len(current_text) + len(word) + 1 <= max_chars:
|
64 |
+
current_text += word + " "
|
65 |
+
else:
|
66 |
+
split_texts.append(current_text)
|
67 |
+
current_text = word + " "
|
68 |
+
split_texts.append(current_text)
|
69 |
+
|
70 |
+
return split_texts
|
71 |
+
|
72 |
+
|
73 |
+
def pdf_to_string(self, file):
|
74 |
+
pdf_data = file.read()
|
75 |
+
pdf_document = PyPDF2.PdfReader(BytesIO(pdf_data))
|
76 |
+
text = ""
|
77 |
+
for page_number in range(len(pdf_document.pages)):
|
78 |
+
text += pdf_document.pages[page_number].extract_text()
|
79 |
+
return text
|
80 |
+
|
81 |
+
def word_to_string(self, file):
|
82 |
+
doc = Document(file)
|
83 |
+
full_text = []
|
84 |
+
|
85 |
+
for para in doc.paragraphs:
|
86 |
+
full_text.append(para.text)
|
87 |
+
|
88 |
+
return '\n'.join(full_text)
|
89 |
+
|
90 |
+
def excel_to_string(self, file):
|
91 |
+
df = pd.read_excel(file)
|
92 |
+
return self.dataframe_to_formatted_string(df)
|
93 |
+
|
94 |
+
def csv_to_string(self, file):
|
95 |
+
df = pd.read_csv(file)
|
96 |
+
return self.dataframe_to_formatted_string(df)
|
97 |
+
|
98 |
+
def dataframe_to_formatted_string(self, df):
|
99 |
+
formatted_string = ', '.join(df.columns) + '\n'
|
100 |
+
|
101 |
+
for index, row in df.iterrows():
|
102 |
+
line_values = [str(value) for value in row]
|
103 |
+
formatted_string += ', '.join(line_values) + '\n'
|
104 |
+
|
105 |
+
return formatted_string.strip()
|
106 |
+
|
Services/__init__.py
ADDED
File without changes
|
Views/chatbot.py
ADDED
@@ -0,0 +1,219 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import requests
|
3 |
+
from Ressources.Config import URL
|
4 |
+
from Ressources.Translations import translations
|
5 |
+
from Services.Service_File import Service_File
|
6 |
+
|
7 |
+
def view_chatbot():
|
8 |
+
chatbot = translations[st.session_state['languages']]['chatbotPage']
|
9 |
+
|
10 |
+
view_history()
|
11 |
+
|
12 |
+
st.title(chatbot['selectedModel'] + " : " + st.session_state['model_selected'])
|
13 |
+
if st.session_state['chat_id'] is None :
|
14 |
+
view_select_model()
|
15 |
+
view_file_upload()
|
16 |
+
|
17 |
+
if st.session_state['chat_id'] is not None :
|
18 |
+
for message in st.session_state['selected_chat']:
|
19 |
+
if message['chat_message_is_ia'] == 1:
|
20 |
+
with st.chat_message("assistant"):
|
21 |
+
st.write(message['chat_message'])
|
22 |
+
else:
|
23 |
+
with st.chat_message("user"):
|
24 |
+
st.write(message['chat_message'])
|
25 |
+
view_chat()
|
26 |
+
|
27 |
+
|
28 |
+
def view_select_model():
|
29 |
+
st.selectbox(
|
30 |
+
translations[st.session_state['languages']]['chatbotPage']['chooseModel'],
|
31 |
+
("Bert", "BigBird", "Splinter", "Squeeze"),
|
32 |
+
index=0,
|
33 |
+
key="model",
|
34 |
+
on_change=function_select_model
|
35 |
+
)
|
36 |
+
|
37 |
+
|
38 |
+
def view_history():
|
39 |
+
Global = translations[st.session_state['languages']]
|
40 |
+
|
41 |
+
function_initialize_history()
|
42 |
+
|
43 |
+
col1, col2, col3 = st.sidebar.columns([3, 1, 1])
|
44 |
+
col1.write(Global['language'])
|
45 |
+
col2.button('EN ', on_click=function_set_language, args=('en',))
|
46 |
+
col3.button('FR ', on_click=function_set_language, args=('fr',))
|
47 |
+
|
48 |
+
col1, col2, col3 = st.sidebar.columns([3, 1, 3])
|
49 |
+
col1.write(st.session_state['user_name'].capitalize())
|
50 |
+
col3.button(translations[st.session_state['languages']]['logout'], on_click=function_logout_user)
|
51 |
+
|
52 |
+
st.sidebar.title('')
|
53 |
+
|
54 |
+
col1, col2, col3 = st.sidebar.columns([3, 1, 1])
|
55 |
+
col1.write(Global['home'])
|
56 |
+
col3.button('➕', on_click=function_new_chat)
|
57 |
+
|
58 |
+
for option in st.session_state.chat_history.values():
|
59 |
+
col1, col2, col3 = st.sidebar.columns([3, 1, 1])
|
60 |
+
col1.write(option['chat_title'], key=f"chat_title_{option['chat_id']}")
|
61 |
+
col2.button('👀', key=f"show_{option['chat_id']}", on_click=function_show_chat, args=(option['chat_id'],))
|
62 |
+
col3.button('🗑️', key=f"del_{option['chat_id']}", on_click=function_delete_chat, args=(option['chat_id'],))
|
63 |
+
|
64 |
+
|
65 |
+
def view_chat():
|
66 |
+
chatbot = translations[st.session_state['languages']]['chatbotPage']
|
67 |
+
st.chat_input(chatbot['enterQuestion'], key='prompt', on_submit=function_send_message)
|
68 |
+
|
69 |
+
|
70 |
+
def view_file_upload():
|
71 |
+
file = st.file_uploader('Upload a file', type=['.docx', '.pdf', '.xlsx', '.csv'])
|
72 |
+
st.write('')
|
73 |
+
|
74 |
+
if st.session_state['is_chat_show'] == False:
|
75 |
+
st.session_state['have_file'] = False
|
76 |
+
st.session_state['file_content'] = ''
|
77 |
+
|
78 |
+
serviceFile = Service_File()
|
79 |
+
string = ''
|
80 |
+
|
81 |
+
if file is not None:
|
82 |
+
|
83 |
+
string += serviceFile.file_for_string(file)
|
84 |
+
st.session_state['have_file'] = True
|
85 |
+
|
86 |
+
st.session_state['file_content'] = string
|
87 |
+
|
88 |
+
|
89 |
+
def function_initialize_history():
|
90 |
+
try:
|
91 |
+
response = requests.get(URL + "/chatHistory", json={
|
92 |
+
'user_id': st.session_state['user_id'],
|
93 |
+
'user_is_connected': st.session_state['user_is_connected'],
|
94 |
+
})
|
95 |
+
|
96 |
+
st.session_state.chat_history = dict(sorted(response.json().items(), key=lambda item: item[1]['chat_date'], reverse=True))
|
97 |
+
|
98 |
+
except Exception as e:
|
99 |
+
st.error(translations[st.session_state['languages']]['generalError'])
|
100 |
+
|
101 |
+
|
102 |
+
def function_send_message():
|
103 |
+
st.session_state['user_question'] = st.session_state['prompt']
|
104 |
+
|
105 |
+
try:
|
106 |
+
response = requests.post(URL + "/predict", json={
|
107 |
+
'user_id': st.session_state['user_id'],
|
108 |
+
'chat_id': st.session_state['chat_id'],
|
109 |
+
'user_is_connected': st.session_state['user_is_connected'],
|
110 |
+
'user_question': st.session_state['user_question'],
|
111 |
+
'file_content': st.session_state['file_content'],
|
112 |
+
'have_file': st.session_state['have_file'],
|
113 |
+
'model_selected': st.session_state['model_selected']
|
114 |
+
})
|
115 |
+
|
116 |
+
content = response.json()
|
117 |
+
|
118 |
+
if st.session_state['chat_id'] == None:
|
119 |
+
st.session_state['chat_id'] = int(content['chat_id'])
|
120 |
+
function_initialize_history()
|
121 |
+
|
122 |
+
st.session_state['user_question'] = ''
|
123 |
+
|
124 |
+
function_show_chat(int(content['chat_id']))
|
125 |
+
|
126 |
+
except Exception as e:
|
127 |
+
st.error(translations[st.session_state['languages']]['generalError'])
|
128 |
+
|
129 |
+
|
130 |
+
def function_new_chat():
|
131 |
+
st.session_state['chat_id'] = None
|
132 |
+
st.session_state['selected_chat'] = None
|
133 |
+
st.session_state['user_question'] = ''
|
134 |
+
st.session_state['file_content'] = None
|
135 |
+
st.session_state['have_file'] = False
|
136 |
+
st.session_state['is_chat_show'] = False
|
137 |
+
st.session_state['model_selected'] = "Bert"
|
138 |
+
|
139 |
+
|
140 |
+
def function_show_chat(chat_id):
|
141 |
+
st.session_state['file_content'] = None
|
142 |
+
st.session_state['have_file'] = False
|
143 |
+
|
144 |
+
try:
|
145 |
+
st.session_state['chat_id'] = int(chat_id)
|
146 |
+
|
147 |
+
chat_message_response = requests.get(URL + "/chatMessage", json={
|
148 |
+
'user_id': st.session_state['user_id'],
|
149 |
+
'user_is_connected': st.session_state['user_is_connected'],
|
150 |
+
'chat_id': chat_id
|
151 |
+
})
|
152 |
+
|
153 |
+
chat_message_content = chat_message_response.json()
|
154 |
+
|
155 |
+
chat_reponse = requests.get(URL + "/getChat", json={
|
156 |
+
'user_id': st.session_state['user_id'],
|
157 |
+
'user_is_connected': st.session_state['user_is_connected'],
|
158 |
+
'chat_id': chat_id
|
159 |
+
})
|
160 |
+
|
161 |
+
chat_content = chat_reponse.json()
|
162 |
+
|
163 |
+
if chat_content[3] is not None:
|
164 |
+
st.session_state['have_file'] = True
|
165 |
+
st.session_state['file_content'] = chat_content[3]
|
166 |
+
|
167 |
+
st.session_state['is_chat_show'] = True
|
168 |
+
st.session_state['selected_chat'] = chat_message_content
|
169 |
+
st.session_state['model_selected'] = st.session_state['chat_history'][str(chat_id)]['chat_model']
|
170 |
+
|
171 |
+
except Exception as e:
|
172 |
+
st.error(translations[st.session_state['languages']]['generalError'])
|
173 |
+
|
174 |
+
|
175 |
+
def function_delete_chat(chat_id):
|
176 |
+
try:
|
177 |
+
requests.post(URL + "/deleteChat", json={
|
178 |
+
'user_id': st.session_state['user_id'],
|
179 |
+
'chat_id': chat_id,
|
180 |
+
'user_is_connected': st.session_state['user_is_connected'],
|
181 |
+
})
|
182 |
+
|
183 |
+
del st.session_state.chat_history[str(chat_id)]
|
184 |
+
|
185 |
+
if st.session_state['chat_id'] == chat_id:
|
186 |
+
st.session_state['model_selected'] = "Bert"
|
187 |
+
st.session_state['chat_id'] = None
|
188 |
+
st.session_state['selected_chat'] = None
|
189 |
+
st.session_state['have_file'] = False
|
190 |
+
st.session_state['file_content'] = None
|
191 |
+
st.session_state['is_chat_show'] = False
|
192 |
+
|
193 |
+
except Exception as e:
|
194 |
+
st.error(translations[st.session_state['languages']]['generalError'])
|
195 |
+
|
196 |
+
|
197 |
+
def function_set_language(locale):
|
198 |
+
st.session_state['languages'] = locale
|
199 |
+
|
200 |
+
|
201 |
+
def function_select_model():
|
202 |
+
st.session_state['model_selected'] = st.session_state['model']
|
203 |
+
|
204 |
+
|
205 |
+
def function_logout_user():
|
206 |
+
st.session_state['user_id'] = None
|
207 |
+
st.session_state['user_name'] = None
|
208 |
+
st.session_state['user_is_connected'] = False
|
209 |
+
st.session_state['chat_history'] = {}
|
210 |
+
st.session_state['selected_chat'] = {}
|
211 |
+
st.session_state['user_question'] = ''
|
212 |
+
st.session_state['chat_id'] = None
|
213 |
+
st.session_state['current_page'] = 'Login'
|
214 |
+
st.session_state['login_pressed'] = False
|
215 |
+
st.session_state['signup_pressed'] = False
|
216 |
+
st.session_state['model_selected'] = "Bert"
|
217 |
+
st.session_state['file_content'] = None
|
218 |
+
st.session_state['is_chat_show'] = False
|
219 |
+
|
Views/login.py
ADDED
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import requests
|
3 |
+
from Ressources.Config import URL
|
4 |
+
from Ressources.Translations import translations
|
5 |
+
|
6 |
+
|
7 |
+
def view_login():
|
8 |
+
Global = translations[st.session_state['languages']]
|
9 |
+
signup = translations[st.session_state['languages']]['loginPage']
|
10 |
+
|
11 |
+
st.title(signup['login'])
|
12 |
+
st.write(signup['description'])
|
13 |
+
|
14 |
+
username = st.text_input(Global["username"], key='username')
|
15 |
+
password = st.text_input(Global["password"], type="password", key='password')
|
16 |
+
|
17 |
+
login_disabled = not username or not password
|
18 |
+
st.button(signup['login'], on_click=function_login_button_pressed, disabled=login_disabled)
|
19 |
+
|
20 |
+
col1, col2, col3 = st.sidebar.columns([3, 1, 1])
|
21 |
+
col1.write(Global['language'])
|
22 |
+
col2.button('EN ', on_click=function_set_language, args=('en',))
|
23 |
+
col3.button('FR ', on_click=function_set_language, args=('fr',))
|
24 |
+
|
25 |
+
col1, col3 = st.sidebar.columns([4, 1])
|
26 |
+
col1.write(signup['createAccount'])
|
27 |
+
col3.button("👋", on_click=function_signup_button_pressed)
|
28 |
+
|
29 |
+
|
30 |
+
def function_login_button_pressed():
|
31 |
+
try:
|
32 |
+
response = requests.post(URL + "/login", json={
|
33 |
+
'username': st.session_state['username'],
|
34 |
+
'password': st.session_state['password']
|
35 |
+
})
|
36 |
+
|
37 |
+
content = response.json()
|
38 |
+
|
39 |
+
if content['state']:
|
40 |
+
st.session_state['current_page'] = 'Chatbot'
|
41 |
+
st.session_state['login_pressed'] = True
|
42 |
+
|
43 |
+
st.session_state['user_id'] = content['user_id']
|
44 |
+
st.session_state['user_name'] = content['user_name']
|
45 |
+
st.session_state['user_is_connected'] = content['user_is_connected']
|
46 |
+
|
47 |
+
st.session_state['username'] = None
|
48 |
+
st.session_state['password'] = None
|
49 |
+
else:
|
50 |
+
st.error(content['message'])
|
51 |
+
|
52 |
+
except Exception as e:
|
53 |
+
st.error(translations[st.session_state['languages']]['generalError'])
|
54 |
+
|
55 |
+
|
56 |
+
def function_signup_button_pressed():
|
57 |
+
st.session_state['current_page'] = 'Signup'
|
58 |
+
st.session_state['signup_pressed'] = True
|
59 |
+
st.session_state['username'] = None
|
60 |
+
st.session_state['password'] = None
|
61 |
+
|
62 |
+
|
63 |
+
def function_set_language(locale):
|
64 |
+
st.session_state['languages'] = locale
|
Views/signup.py
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import requests
|
3 |
+
from Ressources.Config import URL
|
4 |
+
from Ressources.Translations import translations
|
5 |
+
|
6 |
+
|
7 |
+
def view_signup():
|
8 |
+
Global = translations[st.session_state['languages']]
|
9 |
+
signup = translations[st.session_state['languages']]['signupPage']
|
10 |
+
|
11 |
+
st.title(signup['signup'])
|
12 |
+
st.write(signup['description'])
|
13 |
+
|
14 |
+
username = st.text_input(Global["username"], key='username')
|
15 |
+
password = st.text_input(Global["password"], type="password", key='password')
|
16 |
+
|
17 |
+
signup_disabled = not username or not password
|
18 |
+
st.button(signup['signup'], on_click=function_signup_button_pressed, disabled=signup_disabled)
|
19 |
+
|
20 |
+
col1, col2, col3 = st.sidebar.columns([3, 1, 1])
|
21 |
+
col1.write(Global['language'])
|
22 |
+
col2.button('EN ', on_click=function_set_language, args=('en',))
|
23 |
+
col3.button('FR ', on_click=function_set_language, args=('fr',))
|
24 |
+
|
25 |
+
col1, col3 = st.sidebar.columns([4, 1])
|
26 |
+
col1.write(signup['connectAccount'])
|
27 |
+
col3.button("👋", on_click=function_login_button_pressed)
|
28 |
+
|
29 |
+
|
30 |
+
def function_set_language(locale):
|
31 |
+
st.session_state['language'] = locale
|
32 |
+
|
33 |
+
|
34 |
+
def function_signup_button_pressed():
|
35 |
+
try:
|
36 |
+
response = requests.post(URL + "signup", json={
|
37 |
+
'username': st.session_state['username'],
|
38 |
+
'password': st.session_state['password']
|
39 |
+
})
|
40 |
+
message = response.json().get('message', '')
|
41 |
+
|
42 |
+
if response.status_code == 200:
|
43 |
+
st.success(message)
|
44 |
+
st.session_state['current_page'] = 'Login'
|
45 |
+
st.session_state['signup_pressed'] = True
|
46 |
+
st.session_state['username'] = None
|
47 |
+
st.session_state['password'] = None
|
48 |
+
else:
|
49 |
+
st.error(message)
|
50 |
+
|
51 |
+
except Exception as e:
|
52 |
+
st.error(translations[st.session_state['languages']]['generalError'])
|
53 |
+
|
54 |
+
|
55 |
+
def function_login_button_pressed():
|
56 |
+
st.session_state['current_page'] = 'Login'
|
57 |
+
st.session_state['login_pressed'] = True
|
app.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
from Views.login import view_login
|
4 |
+
from Views.signup import view_signup
|
5 |
+
from Views.chatbot import view_chatbot
|
6 |
+
from Ressources.Session import initialize_session
|
7 |
+
|
8 |
+
def main():
|
9 |
+
|
10 |
+
initialize_session()
|
11 |
+
|
12 |
+
if st.session_state['current_page'] == 'Login' and st.session_state['user_is_connected'] == False:
|
13 |
+
view_login()
|
14 |
+
|
15 |
+
if st.session_state['current_page'] == 'Signup' and st.session_state['user_is_connected'] == False:
|
16 |
+
view_signup()
|
17 |
+
|
18 |
+
if st.session_state['current_page'] == 'Chatbot' and st.session_state['user_is_connected'] == True:
|
19 |
+
view_chatbot()
|
20 |
+
|
21 |
+
if __name__ == "__main__":
|
22 |
+
main()
|
requirements.txt
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
requests
|
3 |
+
python-docx
|
4 |
+
pymupdf
|
5 |
+
reportlab
|
6 |
+
googletrans-py
|
7 |
+
PyPDF2
|
8 |
+
openpyxl
|