Spaces:
Running
Running
Florian.Moret
commited on
Commit
·
331c122
1
Parent(s):
ec353f3
maj forme
Browse files
app.py
CHANGED
@@ -1,25 +1,28 @@
|
|
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
|
4 |
|
5 |
-
# Titre de l'application
|
6 |
st.set_page_config(page_title="Expert nutrition volaille", page_icon="🤖")
|
7 |
st.title("Chatbot AI avec l'expert nutrition")
|
|
|
|
|
|
|
8 |
|
9 |
-
|
10 |
|
11 |
-
st.sidebar.header("")
|
12 |
#Choix production
|
13 |
choix_prod = st.sidebar.pills(
|
14 |
"Sur quelle espèce voulez-vous avoir des renseignements ?",
|
15 |
-
("Pondeuse", "Chair"),
|
16 |
-
)
|
17 |
|
18 |
#Niveau vulgarisation
|
19 |
choix_vulgarisation = st.sidebar.pills(
|
20 |
"Quel niveau de vulgarisation souhaitez-vous ? (1- Très vulgarisé 2-Intermédiaire 3-Technique)",
|
21 |
-
("1", "2", "3"),
|
22 |
-
|
23 |
|
24 |
#Années de publication
|
25 |
choix_annee = st.sidebar.slider("Années de publication",
|
@@ -27,32 +30,86 @@ choix_annee = st.sidebar.slider("Années de publication",
|
|
27 |
max_value=2025,
|
28 |
value=(2020,2025))
|
29 |
|
|
|
30 |
|
31 |
-
# Chargement du modèle
|
32 |
@st.cache_data
|
33 |
def load_model():
|
34 |
return pipeline("text-generation", model="gpt2")
|
35 |
|
36 |
model = load_model()
|
|
|
37 |
|
38 |
-
# Interface utilisateur
|
39 |
st.sidebar.header("")
|
40 |
-
user_input = st.
|
41 |
|
42 |
-
if st.button("Envoyer"):
|
43 |
-
if user_input:
|
44 |
-
with st.spinner("
|
45 |
# Génération de la réponse
|
46 |
response = model(user_input, max_length=100, num_return_sequences=1)
|
47 |
bot_response = response[0]['generated_text']
|
48 |
|
49 |
-
st.markdown("**Bot :** " + bot_response)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
else:
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
-
#
|
|
|
54 |
st.markdown("""
|
55 |
<style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
.st-bx {
|
57 |
background-color: #f1f1f1;
|
58 |
border-radius: 10px;
|
@@ -66,4 +123,9 @@ st.markdown("""
|
|
66 |
color: #555;
|
67 |
}
|
68 |
</style>
|
69 |
-
""", unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#region# import libs
|
2 |
import streamlit as st
|
3 |
from transformers import pipeline
|
4 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
5 |
+
#endregion
|
6 |
|
7 |
+
#region# Titre de l'application et mise en page
|
8 |
st.set_page_config(page_title="Expert nutrition volaille", page_icon="🤖")
|
9 |
st.title("Chatbot AI avec l'expert nutrition")
|
10 |
+
st.sidebar.image("img/avril_logo_rvb.jpg")
|
11 |
+
st.sidebar.header("")
|
12 |
+
#endregion
|
13 |
|
14 |
+
#region# Elements graphiques
|
15 |
|
|
|
16 |
#Choix production
|
17 |
choix_prod = st.sidebar.pills(
|
18 |
"Sur quelle espèce voulez-vous avoir des renseignements ?",
|
19 |
+
("Pondeuse", "Chair"),)
|
|
|
20 |
|
21 |
#Niveau vulgarisation
|
22 |
choix_vulgarisation = st.sidebar.pills(
|
23 |
"Quel niveau de vulgarisation souhaitez-vous ? (1- Très vulgarisé 2-Intermédiaire 3-Technique)",
|
24 |
+
("1", "2", "3"),)
|
25 |
+
|
26 |
|
27 |
#Années de publication
|
28 |
choix_annee = st.sidebar.slider("Années de publication",
|
|
|
30 |
max_value=2025,
|
31 |
value=(2020,2025))
|
32 |
|
33 |
+
#endregion
|
34 |
|
35 |
+
#region# Chargement du modèle
|
36 |
@st.cache_data
|
37 |
def load_model():
|
38 |
return pipeline("text-generation", model="gpt2")
|
39 |
|
40 |
model = load_model()
|
41 |
+
#endregion
|
42 |
|
43 |
+
#region# Interface utilisateur
|
44 |
st.sidebar.header("")
|
45 |
+
user_input = st.text_area("Entrez votre question:", placeholder="E.g., quelle est la meilleure alimentation pour les poules pondeuses ?")
|
46 |
|
47 |
+
if st.button("Envoyer la question..."):
|
48 |
+
if user_input and choix_prod and choix_vulgarisation and choix_annee :
|
49 |
+
with st.spinner("Veuillez patienter quelques instants..."):
|
50 |
# Génération de la réponse
|
51 |
response = model(user_input, max_length=100, num_return_sequences=1)
|
52 |
bot_response = response[0]['generated_text']
|
53 |
|
54 |
+
# st.markdown("**Bot :** \\t " + bot_response)
|
55 |
+
# Afficher un titre
|
56 |
+
st.subheader("Réponse :")
|
57 |
+
|
58 |
+
# Ajouter du texte Markdown avec un cadre
|
59 |
+
st.markdown(f"""
|
60 |
+
<div style="border: 2px solid #453103; padding: 15px; border-radius: 10px;">
|
61 |
+
{bot_response}
|
62 |
+
</div>
|
63 |
+
""", unsafe_allow_html=True)
|
64 |
+
|
65 |
+
# Afficher un titre
|
66 |
+
st.subheader("Sources :")
|
67 |
+
|
68 |
+
# Ajouter du texte Markdown avec un cadre
|
69 |
+
st.markdown("""
|
70 |
+
<div style="border: 2px solid #453103; padding: 15px; border-radius: 10px;">
|
71 |
+
Sources
|
72 |
+
</div>
|
73 |
+
""", unsafe_allow_html=True)
|
74 |
+
|
75 |
+
st.markdown("""
|
76 |
+
<div style="border: 2px solid #453103; padding: 15px; border-radius: 10px;">
|
77 |
+
Reviews
|
78 |
+
</div>
|
79 |
+
""", unsafe_allow_html=True)
|
80 |
+
|
81 |
+
|
82 |
+
|
83 |
else:
|
84 |
+
if not user_input:
|
85 |
+
st.warning("Veuillez entrer un message!")
|
86 |
+
if not choix_prod or not choix_vulgarisation or not choix_annee:
|
87 |
+
st.warning("Veuillez compléter les paramètres dans le bandeau latéral de gauche!")
|
88 |
+
#endregion
|
89 |
+
|
90 |
+
# choix_prod, choix_vulgarisation, choix_annee
|
91 |
|
92 |
+
#region# Markdown
|
93 |
+
# Styles CSS pour améliorer l'apparence
|
94 |
st.markdown("""
|
95 |
<style>
|
96 |
+
|
97 |
+
/* Changer la couleur de fond de l'ensemble de l'application */
|
98 |
+
body {
|
99 |
+
background-color: #feffb3; /* Couleur de fond bleu clair (par exemple) */
|
100 |
+
color: #453103; /* Couleur de la police en gris foncé */
|
101 |
+
}
|
102 |
+
|
103 |
+
/* Personnaliser la couleur des titres */
|
104 |
+
h1, h2, h3, h4, h5, h6 {
|
105 |
+
color: #4CAF50; /* Changer la couleur des titres en vert */
|
106 |
+
}
|
107 |
+
|
108 |
+
/* Personnaliser la couleur des paragraphes */
|
109 |
+
p {
|
110 |
+
color: #555555; /* Couleur du texte dans les paragraphes */
|
111 |
+
}
|
112 |
+
|
113 |
.st-bx {
|
114 |
background-color: #f1f1f1;
|
115 |
border-radius: 10px;
|
|
|
123 |
color: #555;
|
124 |
}
|
125 |
</style>
|
126 |
+
""", unsafe_allow_html=True)
|
127 |
+
|
128 |
+
|
129 |
+
|
130 |
+
|
131 |
+
#endregion
|