Spaces:
Running
Running
Florian.Moret
commited on
Commit
·
594261d
1
Parent(s):
c13b6ab
update placeholder
Browse files
app.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
#region# import libs
|
2 |
import streamlit as st
|
3 |
import os
|
4 |
-
|
5 |
from mistralai import Mistral
|
6 |
import numpy as np
|
7 |
# import fitz # PyMuPDF pour extraction PDF
|
@@ -12,7 +11,7 @@ from mistralai import Mistral
|
|
12 |
# from llama_index.core import VectorStoreIndex, SimpleDirectoryReader
|
13 |
# from dotenv import load_dotenv
|
14 |
|
15 |
-
MISTRAL_API_KEY = os.getenv("api_mistral")
|
16 |
model = "mistral-large-latest" #"ministral-8b-latest" # ancien model : 'mistral-large-latest'
|
17 |
mistral_client = Mistral(api_key=MISTRAL_API_KEY)
|
18 |
MAX_TOKENS = 1500
|
@@ -57,7 +56,6 @@ def retrieve_relevant_chunks(question, k=5):
|
|
57 |
return [chunked_docs[i] for i in indices[0]]
|
58 |
#endregion
|
59 |
|
60 |
-
|
61 |
#region# Définition des prompts
|
62 |
def generate_prompts(score:str, type: str, annee_min: str, annee_max:str, context ) -> dict:
|
63 |
"""
|
@@ -252,15 +250,13 @@ def prompt_pipeline(user_prompt: str, niveau_detail: str, type_reponse: str, sou
|
|
252 |
|
253 |
#endregion
|
254 |
|
255 |
-
#region# Titre de l'application et mise en page
|
256 |
st.set_page_config(page_title="VolAI", page_icon="🤖")
|
257 |
-
st.title("VolAI, le chatbot expert nutrition de volailles")
|
258 |
st.sidebar.image("img/avril_logo_rvb.jpg")
|
259 |
st.sidebar.header("")
|
260 |
-
|
261 |
-
|
262 |
-
#region# Elements graphiques
|
263 |
-
|
264 |
#Choix production
|
265 |
choix_prod = st.sidebar.pills(
|
266 |
"Sur quelle espèce voulez-vous avoir des renseignements ?",
|
@@ -268,7 +264,7 @@ choix_prod = st.sidebar.pills(
|
|
268 |
|
269 |
#Niveau vulgarisation
|
270 |
choix_vulgarisation = st.sidebar.pills(
|
271 |
-
"Quel niveau de vulgarisation souhaitez-vous ? (1-
|
272 |
("1", "2", "3"),)
|
273 |
|
274 |
#Années de publication
|
@@ -276,11 +272,10 @@ choix_annee = st.sidebar.slider("Années de publication",
|
|
276 |
min_value=2015,
|
277 |
max_value=2025,
|
278 |
value=(2020,2025))
|
279 |
-
|
280 |
#endregion
|
281 |
|
282 |
#region# Interface utilisateur
|
283 |
-
user_input = st.text_area("Entrez votre question:", placeholder="E.g
|
284 |
|
285 |
if st.button("Envoyer la question..."):
|
286 |
if user_input and choix_prod and choix_vulgarisation and choix_annee :
|
@@ -308,8 +303,6 @@ if st.button("Envoyer la question..."):
|
|
308 |
# """, unsafe_allow_html=True)
|
309 |
|
310 |
# print("prefix = ",response0["prefix"])
|
311 |
-
response = response0["reponse_propre"]
|
312 |
-
bot_response = response
|
313 |
|
314 |
# st.markdown("**Bot :** \\t " + bot_response)
|
315 |
# Afficher un titre
|
@@ -318,10 +311,25 @@ if st.button("Envoyer la question..."):
|
|
318 |
# Ajouter du texte Markdown avec un cadre
|
319 |
st.markdown(f"""
|
320 |
<div style="border: 2px solid #453103; padding: 15px; border-radius: 10px;">
|
321 |
-
{
|
322 |
</div>
|
323 |
""", unsafe_allow_html=True)
|
324 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
325 |
#encadré sources
|
326 |
# # Afficher un titre
|
327 |
# st.subheader("Sources :")
|
|
|
1 |
#region# import libs
|
2 |
import streamlit as st
|
3 |
import os
|
|
|
4 |
from mistralai import Mistral
|
5 |
import numpy as np
|
6 |
# import fitz # PyMuPDF pour extraction PDF
|
|
|
11 |
# from llama_index.core import VectorStoreIndex, SimpleDirectoryReader
|
12 |
# from dotenv import load_dotenv
|
13 |
|
14 |
+
MISTRAL_API_KEY = 'DFtRafUrJnASg1cqrEWNtSMKAjZT4Njp' #os.getenv("api_mistral")
|
15 |
model = "mistral-large-latest" #"ministral-8b-latest" # ancien model : 'mistral-large-latest'
|
16 |
mistral_client = Mistral(api_key=MISTRAL_API_KEY)
|
17 |
MAX_TOKENS = 1500
|
|
|
56 |
return [chunked_docs[i] for i in indices[0]]
|
57 |
#endregion
|
58 |
|
|
|
59 |
#region# Définition des prompts
|
60 |
def generate_prompts(score:str, type: str, annee_min: str, annee_max:str, context ) -> dict:
|
61 |
"""
|
|
|
250 |
|
251 |
#endregion
|
252 |
|
253 |
+
#region# Titre de l'application et mise en page des éléments graphiques
|
254 |
st.set_page_config(page_title="VolAI", page_icon="🤖")
|
255 |
+
st.title("VolAI, le chatbot expert en nutrition de volailles")
|
256 |
st.sidebar.image("img/avril_logo_rvb.jpg")
|
257 |
st.sidebar.header("")
|
258 |
+
|
259 |
+
|
|
|
|
|
260 |
#Choix production
|
261 |
choix_prod = st.sidebar.pills(
|
262 |
"Sur quelle espèce voulez-vous avoir des renseignements ?",
|
|
|
264 |
|
265 |
#Niveau vulgarisation
|
266 |
choix_vulgarisation = st.sidebar.pills(
|
267 |
+
"Quel niveau de vulgarisation souhaitez-vous ? (1- Vulgarisé 2-Intermédiaire 3-Technique)",
|
268 |
("1", "2", "3"),)
|
269 |
|
270 |
#Années de publication
|
|
|
272 |
min_value=2015,
|
273 |
max_value=2025,
|
274 |
value=(2020,2025))
|
|
|
275 |
#endregion
|
276 |
|
277 |
#region# Interface utilisateur
|
278 |
+
user_input = st.text_area("Entrez votre question:", placeholder="E.g.: Quelle est la réponse du GMQ à l'arginine ?")
|
279 |
|
280 |
if st.button("Envoyer la question..."):
|
281 |
if user_input and choix_prod and choix_vulgarisation and choix_annee :
|
|
|
303 |
# """, unsafe_allow_html=True)
|
304 |
|
305 |
# print("prefix = ",response0["prefix"])
|
|
|
|
|
306 |
|
307 |
# st.markdown("**Bot :** \\t " + bot_response)
|
308 |
# Afficher un titre
|
|
|
311 |
# Ajouter du texte Markdown avec un cadre
|
312 |
st.markdown(f"""
|
313 |
<div style="border: 2px solid #453103; padding: 15px; border-radius: 10px;">
|
314 |
+
{response0["reponse_propre"]}
|
315 |
</div>
|
316 |
""", unsafe_allow_html=True)
|
317 |
|
318 |
+
response1 = prompt_pipeline(
|
319 |
+
user_prompt = user_input,
|
320 |
+
niveau_detail=choix_vulgarisation,
|
321 |
+
type_reponse=choix_prod,
|
322 |
+
souche=None,
|
323 |
+
context='',
|
324 |
+
annee_publication_max=max(choix_annee),
|
325 |
+
annee_publication_min=min(choix_annee)
|
326 |
+
)
|
327 |
+
st.subheader("Réponse sans contexte :")
|
328 |
+
st.markdown(f"""
|
329 |
+
<div style="border: 2px solid #453103; padding: 15px; border-radius: 10px;">
|
330 |
+
{response1['reponse_propre']}
|
331 |
+
</div>
|
332 |
+
""", unsafe_allow_html=True)
|
333 |
#encadré sources
|
334 |
# # Afficher un titre
|
335 |
# st.subheader("Sources :")
|