Update app.py
Browse files
app.py
CHANGED
|
@@ -1,197 +1,197 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
from streamlit_option_menu import option_menu
|
| 3 |
-
import openai
|
| 4 |
-
from streamlit_chat import message
|
| 5 |
-
#importation des librairies
|
| 6 |
-
import pandas as pd
|
| 7 |
-
|
| 8 |
-
st.set_page_config(layout='wide')
|
| 9 |
-
st.markdown("""
|
| 10 |
-
<style>
|
| 11 |
-
.block-container {
|
| 12 |
-
padding-top: 2rem;
|
| 13 |
-
padding-bottom: 0rem;
|
| 14 |
-
padding-left: 1rem;
|
| 15 |
-
padding-right: 1rem;
|
| 16 |
-
}
|
| 17 |
-
</style>
|
| 18 |
-
""", unsafe_allow_html=True)
|
| 19 |
-
|
| 20 |
-
openai.api_key = "sk-proj-RExBXqnjaTYCWwB3aQOOT3BlbkFJJf9S2nbyQj11VfArtjjo"
|
| 21 |
-
|
| 22 |
-
def api_calling(prompt):
|
| 23 |
-
completions = openai.Completion.create(
|
| 24 |
-
engine="gpt-3.5-turbo-instruct",
|
| 25 |
-
prompt=prompt,
|
| 26 |
-
max_tokens=1024,
|
| 27 |
-
n=1,
|
| 28 |
-
stop=None,
|
| 29 |
-
temperature=0.5,
|
| 30 |
-
)
|
| 31 |
-
message = completions.choices[0].text
|
| 32 |
-
return message
|
| 33 |
-
header , menu = st.columns(2)
|
| 34 |
-
|
| 35 |
-
with header:
|
| 36 |
-
st.image('static/img/teacherbot.
|
| 37 |
-
|
| 38 |
-
with menu:
|
| 39 |
-
# option_menu(menu_title=None,
|
| 40 |
-
# options=['Visualisation','Prédiction'],
|
| 41 |
-
# icons=["house","book",'envelope'],
|
| 42 |
-
# default_index=0,
|
| 43 |
-
# orientation="horizontal"
|
| 44 |
-
# )
|
| 45 |
-
selecte=option_menu(None, ["Accueil", "Se déconnecter"],
|
| 46 |
-
icons=['house', 'cloud-upload'],
|
| 47 |
-
menu_icon="cast", default_index=0, orientation="horizontal",
|
| 48 |
-
styles={
|
| 49 |
-
"container": {"padding": "0!important", "background-color": "#fafafa","font-family": "Impact, Haettenschweiler, 'Arial Narrow Bold', sans-serif"},
|
| 50 |
-
"icon": {"color": "orange", "font-size": "25px" },
|
| 51 |
-
"nav-link": {"font-size": "20px", "text-align": "left", "margin":"0px", "--hover-color": "#eee"},
|
| 52 |
-
"nav-link-selected": {"background-color": "#70ad46","color":"white"},
|
| 53 |
-
"menu-title":{"color":"#424143"}
|
| 54 |
-
}
|
| 55 |
-
)
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
if selecte == "Accueil":
|
| 59 |
-
st.title(f"Bienvenu au cours d'informatique de la classe de 3ieme")
|
| 60 |
-
sect1_col1=st.container()
|
| 61 |
-
sect1_col2 = st.container()
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
with open('static/css/style.css') as f:
|
| 65 |
-
st.markdown(f'<style>{f.read()}</style>', unsafe_allow_html=True)
|
| 66 |
-
with sect1_col1.container(height=700):
|
| 67 |
-
|
| 68 |
-
st.selectbox("Quelle UE voulez-vous preparer?",("Informatique","Mathematique","Physique"))
|
| 69 |
-
st.selectbox("De quel UA s'agit-il?",("Decrire les peripheriques","Decrire les logiciels","Assurer le bon fonctionnement de l'ordinateur","utiliser les fonctions d'un tableur"))
|
| 70 |
-
if 'user_input' not in st.session_state:
|
| 71 |
-
st.session_state['user_input'] = []
|
| 72 |
-
|
| 73 |
-
if 'openai_response' not in st.session_state:
|
| 74 |
-
st.session_state['openai_response'] = []
|
| 75 |
-
|
| 76 |
-
def get_text():
|
| 77 |
-
input_text = st.text_input("Quelles sont les objectifs du programme concerné?", key="input")
|
| 78 |
-
return input_text
|
| 79 |
-
|
| 80 |
-
user_input = get_text()
|
| 81 |
-
|
| 82 |
-
if user_input:
|
| 83 |
-
output = api_calling(user_input)
|
| 84 |
-
output = output.lstrip("\n")
|
| 85 |
-
|
| 86 |
-
# Store the output
|
| 87 |
-
st.session_state.openai_response.append(user_input)
|
| 88 |
-
st.session_state.user_input.append(output)
|
| 89 |
-
|
| 90 |
-
message_history = st.empty()
|
| 91 |
-
|
| 92 |
-
if st.session_state['user_input']:
|
| 93 |
-
for i in range(len(st.session_state['user_input']) - 1, -1, -1):
|
| 94 |
-
# This function displays user input
|
| 95 |
-
message(st.session_state["user_input"][i],
|
| 96 |
-
key=str(i),avatar_style="icons")
|
| 97 |
-
# This function displays OpenAI response
|
| 98 |
-
message(st.session_state['openai_response'][i],
|
| 99 |
-
avatar_style="miniavs",is_user=True,
|
| 100 |
-
key=str(i) + 'data_by_user')
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
st.markdown("""
|
| 104 |
-
<style>
|
| 105 |
-
# div[data-testid="stMetric"] {
|
| 106 |
-
# background-color: rgba(187, 216, 158, 0.59);
|
| 107 |
-
# border: 1px solid rgba(28, 131, 225, 0.1);
|
| 108 |
-
padding:-10px;
|
| 109 |
-
# border-radius: 5px;
|
| 110 |
-
# color: rgb(30, 103, 119);
|
| 111 |
-
# overflow-wrap: break-word;
|
| 112 |
-
# font-weight:bold;
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
# }
|
| 116 |
-
|
| 117 |
-
[data-testid="stMetricValue"]{
|
| 118 |
-
font-size: 45px;
|
| 119 |
-
color: #2FB56B;
|
| 120 |
-
font-weight:bold;
|
| 121 |
-
text-align:center;
|
| 122 |
-
margin-top:-33px;
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
}
|
| 127 |
-
|
| 128 |
-
/* breakline for metric text */
|
| 129 |
-
[data-testid="stMetricLabel"] {
|
| 130 |
-
word-wrap: break-word;
|
| 131 |
-
color: #ef8451;
|
| 132 |
-
font-size:40px;
|
| 133 |
-
font-weight:bold;
|
| 134 |
-
|
| 135 |
-
}
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
[data-testid ="stVerticalBlock"]{
|
| 139 |
-
#background-color: rgba(187, 216, 158, 0.59);
|
| 140 |
-
#border: 1px solid rgba(28, 131, 225, 0.1);
|
| 141 |
-
text-align:center;
|
| 142 |
-
}
|
| 143 |
-
[data-v-5af006b8]{
|
| 144 |
-
background-color:black;
|
| 145 |
-
}
|
| 146 |
-
.st-emotion-cache-sr3x2q{
|
| 147 |
-
width:80%;
|
| 148 |
-
margin-left:10%;
|
| 149 |
-
margin-right:10%;
|
| 150 |
-
height: 50% !important;
|
| 151 |
-
}
|
| 152 |
-
.st-emotion-cache-7ym5gk{
|
| 153 |
-
background-color: #70ad46;
|
| 154 |
-
color:white;
|
| 155 |
-
}
|
| 156 |
-
</style>
|
| 157 |
-
"""
|
| 158 |
-
, unsafe_allow_html=True)
|
| 159 |
-
footer = st.container()
|
| 160 |
-
with footer:
|
| 161 |
-
st.markdown("---")
|
| 162 |
-
st.markdown(
|
| 163 |
-
"""
|
| 164 |
-
<style>
|
| 165 |
-
p {
|
| 166 |
-
font-size: 16px;
|
| 167 |
-
text-align: center;
|
| 168 |
-
}
|
| 169 |
-
a {
|
| 170 |
-
text-decoration: none;
|
| 171 |
-
color: #00a;
|
| 172 |
-
font-weight: 600;
|
| 173 |
-
}
|
| 174 |
-
</style>
|
| 175 |
-
<p>
|
| 176 |
-
© Designed by <a href="#"></a>.
|
| 177 |
-
</p>
|
| 178 |
-
""", unsafe_allow_html=True
|
| 179 |
-
)
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
if selecte == "Données":
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
st.title(f"Les Capteurs en NAIROBI,KENYA")
|
| 190 |
-
st_folium(map,width=2000,height=600)
|
| 191 |
-
st.title(f"DATA")
|
| 192 |
-
moi = st.columns(1)
|
| 193 |
-
|
| 194 |
-
placeholder = st.empty()
|
| 195 |
-
df_all_concatenated_transform_daily= df_all_concatenated_transform_daily[df_all_concatenated_transform_daily["Moi"] ==moi_filtre]
|
| 196 |
-
|
| 197 |
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from streamlit_option_menu import option_menu
|
| 3 |
+
import openai
|
| 4 |
+
from streamlit_chat import message
|
| 5 |
+
#importation des librairies
|
| 6 |
+
import pandas as pd
|
| 7 |
+
|
| 8 |
+
st.set_page_config(layout='wide')
|
| 9 |
+
st.markdown("""
|
| 10 |
+
<style>
|
| 11 |
+
.block-container {
|
| 12 |
+
padding-top: 2rem;
|
| 13 |
+
padding-bottom: 0rem;
|
| 14 |
+
padding-left: 1rem;
|
| 15 |
+
padding-right: 1rem;
|
| 16 |
+
}
|
| 17 |
+
</style>
|
| 18 |
+
""", unsafe_allow_html=True)
|
| 19 |
+
|
| 20 |
+
openai.api_key = "sk-proj-RExBXqnjaTYCWwB3aQOOT3BlbkFJJf9S2nbyQj11VfArtjjo"
|
| 21 |
+
|
| 22 |
+
def api_calling(prompt):
|
| 23 |
+
completions = openai.Completion.create(
|
| 24 |
+
engine="gpt-3.5-turbo-instruct",
|
| 25 |
+
prompt=prompt,
|
| 26 |
+
max_tokens=1024,
|
| 27 |
+
n=1,
|
| 28 |
+
stop=None,
|
| 29 |
+
temperature=0.5,
|
| 30 |
+
)
|
| 31 |
+
message = completions.choices[0].text
|
| 32 |
+
return message
|
| 33 |
+
header , menu = st.columns(2)
|
| 34 |
+
|
| 35 |
+
with header:
|
| 36 |
+
st.image('static/img/teacherbot.PNG')
|
| 37 |
+
|
| 38 |
+
with menu:
|
| 39 |
+
# option_menu(menu_title=None,
|
| 40 |
+
# options=['Visualisation','Prédiction'],
|
| 41 |
+
# icons=["house","book",'envelope'],
|
| 42 |
+
# default_index=0,
|
| 43 |
+
# orientation="horizontal"
|
| 44 |
+
# )
|
| 45 |
+
selecte=option_menu(None, ["Accueil", "Se déconnecter"],
|
| 46 |
+
icons=['house', 'cloud-upload'],
|
| 47 |
+
menu_icon="cast", default_index=0, orientation="horizontal",
|
| 48 |
+
styles={
|
| 49 |
+
"container": {"padding": "0!important", "background-color": "#fafafa","font-family": "Impact, Haettenschweiler, 'Arial Narrow Bold', sans-serif"},
|
| 50 |
+
"icon": {"color": "orange", "font-size": "25px" },
|
| 51 |
+
"nav-link": {"font-size": "20px", "text-align": "left", "margin":"0px", "--hover-color": "#eee"},
|
| 52 |
+
"nav-link-selected": {"background-color": "#70ad46","color":"white"},
|
| 53 |
+
"menu-title":{"color":"#424143"}
|
| 54 |
+
}
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
if selecte == "Accueil":
|
| 59 |
+
st.title(f"Bienvenu au cours d'informatique de la classe de 3ieme")
|
| 60 |
+
sect1_col1=st.container()
|
| 61 |
+
sect1_col2 = st.container()
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
with open('static/css/style.css') as f:
|
| 65 |
+
st.markdown(f'<style>{f.read()}</style>', unsafe_allow_html=True)
|
| 66 |
+
with sect1_col1.container(height=700):
|
| 67 |
+
|
| 68 |
+
st.selectbox("Quelle UE voulez-vous preparer?",("Informatique","Mathematique","Physique"))
|
| 69 |
+
st.selectbox("De quel UA s'agit-il?",("Decrire les peripheriques","Decrire les logiciels","Assurer le bon fonctionnement de l'ordinateur","utiliser les fonctions d'un tableur"))
|
| 70 |
+
if 'user_input' not in st.session_state:
|
| 71 |
+
st.session_state['user_input'] = []
|
| 72 |
+
|
| 73 |
+
if 'openai_response' not in st.session_state:
|
| 74 |
+
st.session_state['openai_response'] = []
|
| 75 |
+
|
| 76 |
+
def get_text():
|
| 77 |
+
input_text = st.text_input("Quelles sont les objectifs du programme concerné?", key="input")
|
| 78 |
+
return input_text
|
| 79 |
+
|
| 80 |
+
user_input = get_text()
|
| 81 |
+
|
| 82 |
+
if user_input:
|
| 83 |
+
output = api_calling(user_input)
|
| 84 |
+
output = output.lstrip("\n")
|
| 85 |
+
|
| 86 |
+
# Store the output
|
| 87 |
+
st.session_state.openai_response.append(user_input)
|
| 88 |
+
st.session_state.user_input.append(output)
|
| 89 |
+
|
| 90 |
+
message_history = st.empty()
|
| 91 |
+
|
| 92 |
+
if st.session_state['user_input']:
|
| 93 |
+
for i in range(len(st.session_state['user_input']) - 1, -1, -1):
|
| 94 |
+
# This function displays user input
|
| 95 |
+
message(st.session_state["user_input"][i],
|
| 96 |
+
key=str(i),avatar_style="icons")
|
| 97 |
+
# This function displays OpenAI response
|
| 98 |
+
message(st.session_state['openai_response'][i],
|
| 99 |
+
avatar_style="miniavs",is_user=True,
|
| 100 |
+
key=str(i) + 'data_by_user')
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
st.markdown("""
|
| 104 |
+
<style>
|
| 105 |
+
# div[data-testid="stMetric"] {
|
| 106 |
+
# background-color: rgba(187, 216, 158, 0.59);
|
| 107 |
+
# border: 1px solid rgba(28, 131, 225, 0.1);
|
| 108 |
+
padding:-10px;
|
| 109 |
+
# border-radius: 5px;
|
| 110 |
+
# color: rgb(30, 103, 119);
|
| 111 |
+
# overflow-wrap: break-word;
|
| 112 |
+
# font-weight:bold;
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
# }
|
| 116 |
+
|
| 117 |
+
[data-testid="stMetricValue"]{
|
| 118 |
+
font-size: 45px;
|
| 119 |
+
color: #2FB56B;
|
| 120 |
+
font-weight:bold;
|
| 121 |
+
text-align:center;
|
| 122 |
+
margin-top:-33px;
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
/* breakline for metric text */
|
| 129 |
+
[data-testid="stMetricLabel"] {
|
| 130 |
+
word-wrap: break-word;
|
| 131 |
+
color: #ef8451;
|
| 132 |
+
font-size:40px;
|
| 133 |
+
font-weight:bold;
|
| 134 |
+
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
[data-testid ="stVerticalBlock"]{
|
| 139 |
+
#background-color: rgba(187, 216, 158, 0.59);
|
| 140 |
+
#border: 1px solid rgba(28, 131, 225, 0.1);
|
| 141 |
+
text-align:center;
|
| 142 |
+
}
|
| 143 |
+
[data-v-5af006b8]{
|
| 144 |
+
background-color:black;
|
| 145 |
+
}
|
| 146 |
+
.st-emotion-cache-sr3x2q{
|
| 147 |
+
width:80%;
|
| 148 |
+
margin-left:10%;
|
| 149 |
+
margin-right:10%;
|
| 150 |
+
height: 50% !important;
|
| 151 |
+
}
|
| 152 |
+
.st-emotion-cache-7ym5gk{
|
| 153 |
+
background-color: #70ad46;
|
| 154 |
+
color:white;
|
| 155 |
+
}
|
| 156 |
+
</style>
|
| 157 |
+
"""
|
| 158 |
+
, unsafe_allow_html=True)
|
| 159 |
+
footer = st.container()
|
| 160 |
+
with footer:
|
| 161 |
+
st.markdown("---")
|
| 162 |
+
st.markdown(
|
| 163 |
+
"""
|
| 164 |
+
<style>
|
| 165 |
+
p {
|
| 166 |
+
font-size: 16px;
|
| 167 |
+
text-align: center;
|
| 168 |
+
}
|
| 169 |
+
a {
|
| 170 |
+
text-decoration: none;
|
| 171 |
+
color: #00a;
|
| 172 |
+
font-weight: 600;
|
| 173 |
+
}
|
| 174 |
+
</style>
|
| 175 |
+
<p>
|
| 176 |
+
© Designed by <a href="#"></a>.
|
| 177 |
+
</p>
|
| 178 |
+
""", unsafe_allow_html=True
|
| 179 |
+
)
|
| 180 |
+
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
if selecte == "Données":
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
st.title(f"Les Capteurs en NAIROBI,KENYA")
|
| 190 |
+
st_folium(map,width=2000,height=600)
|
| 191 |
+
st.title(f"DATA")
|
| 192 |
+
moi = st.columns(1)
|
| 193 |
+
|
| 194 |
+
placeholder = st.empty()
|
| 195 |
+
df_all_concatenated_transform_daily= df_all_concatenated_transform_daily[df_all_concatenated_transform_daily["Moi"] ==moi_filtre]
|
| 196 |
+
|
| 197 |
|