Spaces:
Runtime error
Runtime error
app with chatbot
Browse files- APIs/geolocation.py +0 -7
- app.py +35 -17
- requirements.txt +0 -0
- utils.py +63 -0
APIs/geolocation.py
CHANGED
@@ -53,10 +53,3 @@ def get_risques(code_insee):
|
|
53 |
else:
|
54 |
risques = None
|
55 |
return risques
|
56 |
-
|
57 |
-
|
58 |
-
if __name__ == "__main__":
|
59 |
-
lon, lat, code_insee = get_geolocation(
|
60 |
-
"6 allée de chartres 91370 Verrieres le Buisson", None, None)
|
61 |
-
|
62 |
-
print(get_risques(code_insee))
|
|
|
53 |
else:
|
54 |
risques = None
|
55 |
return risques
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.py
CHANGED
@@ -1,18 +1,26 @@
|
|
1 |
import gradio as gr
|
2 |
from utils import *
|
3 |
|
|
|
4 |
with gr.Blocks() as demo:
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
6 |
with gr.Column():
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
|
|
|
|
16 |
"Bovin",
|
17 |
"Ovin",
|
18 |
"Caprin",
|
@@ -20,16 +28,26 @@ with gr.Blocks() as demo:
|
|
20 |
"Volailles",
|
21 |
"Equin"
|
22 |
], label="Type d'élevage", info="Quel est votre type d'élevage?")
|
23 |
-
|
24 |
btn = gr.Button(value="Submit", size="sm")
|
25 |
|
26 |
-
|
27 |
-
|
|
|
|
|
|
|
|
|
28 |
|
29 |
-
with gr.
|
30 |
-
|
|
|
|
|
|
|
31 |
|
32 |
-
demo.load(
|
33 |
-
btn.click(
|
|
|
|
|
34 |
|
|
|
35 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from utils import *
|
3 |
|
4 |
+
|
5 |
with gr.Blocks() as demo:
|
6 |
+
temperature = gr.Number(visible=False)
|
7 |
+
humidite = gr.Number(visible=False)
|
8 |
+
meteo = gr.Textbox(visible=False)
|
9 |
+
gr.Markdown(
|
10 |
+
"## GAIA Démo \nDémo avec Mistral AI & LlamaIndex afin d'estimer les risques sanitaires d'un élevage.")
|
11 |
+
with gr.Row(equal_height=True):
|
12 |
with gr.Column():
|
13 |
+
with gr.Tab("Adresse"):
|
14 |
+
address = gr.Textbox(
|
15 |
+
label="Address",
|
16 |
+
info="Dans le cas ou vous ne connaissez pas vos coordonnées GPS, rentrez votre adresse !"
|
17 |
+
)
|
18 |
+
with gr.Tab("Coordonnées GPS"):
|
19 |
+
lat = gr.Number(value=48.832408, label="Latitude",
|
20 |
+
info="La latitude de votre élevage")
|
21 |
+
lon = gr.Number(value=2.28619, label="Longitude",
|
22 |
+
info="La longitude de votre élevage")
|
23 |
+
type_elevage = gr.Radio(choices=[
|
24 |
"Bovin",
|
25 |
"Ovin",
|
26 |
"Caprin",
|
|
|
28 |
"Volailles",
|
29 |
"Equin"
|
30 |
], label="Type d'élevage", info="Quel est votre type d'élevage?")
|
31 |
+
|
32 |
btn = gr.Button(value="Submit", size="sm")
|
33 |
|
34 |
+
with gr.Column():
|
35 |
+
with gr.Tab("Map"):
|
36 |
+
map = gr.HTML()
|
37 |
+
|
38 |
+
with gr.Tab("Weather data"):
|
39 |
+
fig = gr.Plot(label="Météo")
|
40 |
|
41 |
+
with gr.Row():
|
42 |
+
chatbot = gr.Chatbot()
|
43 |
+
msg = gr.Textbox(
|
44 |
+
placeholder="Vous pouvez me poser une question, appuyez sur Entrée pour valider")
|
45 |
+
clear = gr.ClearButton([msg, chatbot])
|
46 |
|
47 |
+
demo.load(on_init, [lat, lon, address], [map, fig, temperature, humidite])
|
48 |
+
btn.click(on_init, [lat, lon, address], [map, fig])
|
49 |
+
msg.submit(respond, [type_elevage, temperature,
|
50 |
+
humidite, meteo, msg, chatbot], [msg, chatbot])
|
51 |
|
52 |
+
demo.title = "Démo GAIA - Les 5 Mousquetaires"
|
53 |
demo.launch()
|
requirements.txt
CHANGED
Binary files a/requirements.txt and b/requirements.txt differ
|
|
utils.py
CHANGED
@@ -4,6 +4,69 @@ from folium import IFrame
|
|
4 |
import plotly.graph_objects as go
|
5 |
from APIs.geolocation import get_geolocation, get_risques
|
6 |
from APIs.meteo import get_info_meteo
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
|
9 |
def get_and_plot_meteo(lat, lon):
|
|
|
4 |
import plotly.graph_objects as go
|
5 |
from APIs.geolocation import get_geolocation, get_risques
|
6 |
from APIs.meteo import get_info_meteo
|
7 |
+
import os
|
8 |
+
from dotenv import load_dotenv
|
9 |
+
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader
|
10 |
+
from llama_index.llms.mistralai import MistralAI
|
11 |
+
from llama_index.embeddings.mistralai import MistralAIEmbedding
|
12 |
+
from llama_index.core import Settings
|
13 |
+
from llama_index.core.query_engine import RetrieverQueryEngine
|
14 |
+
|
15 |
+
load_dotenv()
|
16 |
+
|
17 |
+
Settings.llm = MistralAI(
|
18 |
+
max_tokens=1024,
|
19 |
+
api_key=os.environ.get('MISTRAL_API_KEY')
|
20 |
+
)
|
21 |
+
|
22 |
+
Settings.embed_model = MistralAIEmbedding(
|
23 |
+
model_name="mistral-embed",
|
24 |
+
api_key=os.environ.get('MISTRAL_API_KEY')
|
25 |
+
)
|
26 |
+
|
27 |
+
documents = SimpleDirectoryReader("documents").load_data()
|
28 |
+
index = VectorStoreIndex.from_documents(documents)
|
29 |
+
query_engine = index.as_query_engine(similarity_top_k=15)
|
30 |
+
|
31 |
+
|
32 |
+
def on_init(lat, lon, address):
|
33 |
+
print('titi')
|
34 |
+
map_html, fig = show_map(lat, lon, address)
|
35 |
+
df = get_info_meteo(lat, lon)
|
36 |
+
avg_temp = df.loc[:, 'avg_hourly_soil_temperature_0cm_C'].mean()
|
37 |
+
avg_humidity = df.loc[:, 'avg_hourly_soil_moisture_0_to_1cm_m³'].mean()
|
38 |
+
|
39 |
+
print('toto')
|
40 |
+
return map_html, fig, avg_temp, avg_humidity
|
41 |
+
|
42 |
+
|
43 |
+
def print_conversation(chat_history):
|
44 |
+
for question, response in chat_history:
|
45 |
+
print('Question: ', end='\n')
|
46 |
+
print(question, end='\n')
|
47 |
+
print('Response: ', end='\n')
|
48 |
+
print(response, end='\n')
|
49 |
+
|
50 |
+
|
51 |
+
def respond(elevage, temperature, humidite, meteo, message, chat_history):
|
52 |
+
PROMPT = f"""
|
53 |
+
Tu es un chatbot qui répond en français, qui doit aider à déterminer les risques parasitaires d'élevage en fonction des conditions météorologiques.
|
54 |
+
Voici les conditions:
|
55 |
+
- élevage: {elevage}
|
56 |
+
- température moyenne : {temperature}
|
57 |
+
- humidité moyenne : {humidite}
|
58 |
+
- météo : {meteo}
|
59 |
+
|
60 |
+
{message}
|
61 |
+
|
62 |
+
Donne-moi ensuite les solutions de prévention et de traitement pour chacun d'eux indépendamment du tableau.
|
63 |
+
Tu dois impérativement répondre en français"""
|
64 |
+
|
65 |
+
reponse = query_engine.query(PROMPT)
|
66 |
+
chat_history.append((message, str(reponse)))
|
67 |
+
|
68 |
+
print_conversation(chat_history)
|
69 |
+
return '', chat_history
|
70 |
|
71 |
|
72 |
def get_and_plot_meteo(lat, lon):
|