Spaces:
Paused
Paused
add meteo data + intro reformulee
Browse files- APIs/__pycache__/geolocation.cpython-311.pyc +0 -0
- APIs/__pycache__/meteo.cpython-311.pyc +0 -0
- APIs/meteo.py +43 -35
- app.py +16 -5
- utils.py +11 -6
APIs/__pycache__/geolocation.cpython-311.pyc
CHANGED
Binary files a/APIs/__pycache__/geolocation.cpython-311.pyc and b/APIs/__pycache__/geolocation.cpython-311.pyc differ
|
|
APIs/__pycache__/meteo.cpython-311.pyc
CHANGED
Binary files a/APIs/__pycache__/meteo.cpython-311.pyc and b/APIs/__pycache__/meteo.cpython-311.pyc differ
|
|
APIs/meteo.py
CHANGED
@@ -5,9 +5,9 @@ from retry_requests import retry
|
|
5 |
|
6 |
|
7 |
# Setup the Open-Meteo API client with cache and retry on error
|
8 |
-
cache_session = requests_cache.CachedSession('.cache', expire_after=3600)
|
9 |
-
retry_session = retry(cache_session, retries=5, backoff_factor=0.2)
|
10 |
-
openmeteo = openmeteo_requests.Client(session=retry_session)
|
11 |
|
12 |
|
13 |
def get_info_meteo(latitude, longitude):
|
@@ -15,63 +15,70 @@ def get_info_meteo(latitude, longitude):
|
|
15 |
ARGS:
|
16 |
latitude (Float) : latitude coordinate
|
17 |
longitude (Float): longitude coordinate
|
18 |
-
|
19 |
"""
|
20 |
-
|
21 |
url = "https://api.open-meteo.com/v1/forecast"
|
22 |
params = {
|
23 |
-
"latitude": latitude,
|
24 |
-
"longitude": longitude,
|
25 |
-
"hourly": {"relative_humidity_2m", "soil_temperature_0cm", "soil_moisture_0_to_1cm"},
|
26 |
-
"daily": {"temperature_2m_max",
|
27 |
-
"past_days":
|
28 |
-
"forecast_days": 7
|
29 |
-
|
30 |
-
}
|
31 |
-
|
32 |
responses = openmeteo.weather_api(url, params=params)
|
33 |
response = responses[0]
|
34 |
|
35 |
-
#
|
|
|
36 |
hourly = response.Hourly()
|
37 |
hourly_relative_humidity_2m = hourly.Variables(0).ValuesAsNumpy()
|
38 |
hourly_soil_temperature_0cm = hourly.Variables(1).ValuesAsNumpy()
|
39 |
hourly_soil_moisture_0_to_1cm = hourly.Variables(2).ValuesAsNumpy()
|
|
|
40 |
|
41 |
hourly_data = {"date": pd.date_range(
|
42 |
-
start=pd.to_datetime(hourly.Time(), unit="s", utc=True),
|
43 |
-
end=pd.to_datetime(hourly.TimeEnd(), unit="s", utc=True),
|
44 |
-
freq=pd.Timedelta(seconds=hourly.Interval()),
|
45 |
-
inclusive="left"
|
46 |
)}
|
47 |
|
48 |
hourly_data["relative_humidity_2m_%"] = hourly_relative_humidity_2m
|
49 |
hourly_data["soil_temperature_0cm_C"] = hourly_soil_temperature_0cm
|
50 |
hourly_data["soil_moisture_0_to_1cm_m³"] = hourly_soil_moisture_0_to_1cm
|
|
|
51 |
|
52 |
-
hourly_dataframe = pd.DataFrame(data=hourly_data)
|
53 |
|
54 |
-
# Average hourly data per day
|
55 |
-
hourly_dataframe['day_date'] = hourly_dataframe['date'].dt.strftime(
|
56 |
-
'%Y-%m-%d')
|
57 |
|
58 |
-
|
59 |
-
['relative_humidity_2m_%', 'soil_temperature_0cm_C', 'soil_moisture_0_to_1cm_m³']].mean()
|
60 |
|
61 |
-
|
62 |
-
|
63 |
|
64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
daily = response.Daily()
|
66 |
daily_temperature_2m_max = daily.Variables(0).ValuesAsNumpy()
|
67 |
daily_precipitation_sum = daily.Variables(1).ValuesAsNumpy()
|
68 |
daily_wind_speed_10m_max = daily.Variables(2).ValuesAsNumpy()
|
69 |
daily_sunshine_duration = daily.Variables(3).ValuesAsNumpy()
|
|
|
70 |
|
71 |
daily_data = {"date": pd.date_range(
|
72 |
start=pd.to_datetime(daily.Time(), unit="s", utc=True),
|
73 |
end=pd.to_datetime(daily.TimeEnd(), unit="s", utc=True),
|
74 |
-
freq='D',
|
75 |
inclusive="left"
|
76 |
)}
|
77 |
|
@@ -79,16 +86,17 @@ def get_info_meteo(latitude, longitude):
|
|
79 |
daily_data["daily_precipitation_sum_mm"] = daily_precipitation_sum
|
80 |
daily_data["daily_wind_speed_10m_max_km/h"] = daily_wind_speed_10m_max
|
81 |
daily_data["daily_sunshine_duration_sec"] = daily_sunshine_duration
|
|
|
82 |
|
83 |
daily_dataframe = pd.DataFrame(data=daily_data)
|
84 |
|
85 |
-
daily_dataframe['day_date'] = daily_dataframe['date'].dt.strftime(
|
86 |
-
|
87 |
-
total_df = pd.merge(daily_dataframe, avg_hourly_dataframe,
|
88 |
-
|
89 |
|
90 |
total_df['date'] = total_df['day_date']
|
91 |
total_df = total_df.drop('day_date', axis=1)
|
92 |
-
|
93 |
return total_df
|
94 |
-
#total_df.to_json("
|
|
|
5 |
|
6 |
|
7 |
# Setup the Open-Meteo API client with cache and retry on error
|
8 |
+
cache_session = requests_cache.CachedSession('.cache', expire_after = 3600)
|
9 |
+
retry_session = retry(cache_session, retries = 5, backoff_factor = 0.2)
|
10 |
+
openmeteo = openmeteo_requests.Client(session = retry_session)
|
11 |
|
12 |
|
13 |
def get_info_meteo(latitude, longitude):
|
|
|
15 |
ARGS:
|
16 |
latitude (Float) : latitude coordinate
|
17 |
longitude (Float): longitude coordinate
|
18 |
+
|
19 |
"""
|
|
|
20 |
url = "https://api.open-meteo.com/v1/forecast"
|
21 |
params = {
|
22 |
+
"latitude": latitude,
|
23 |
+
"longitude": longitude, #"cloud_cover_low", "cloud_cover_mid","cloud_cover_high"
|
24 |
+
"hourly": {"relative_humidity_2m", "soil_temperature_0cm", "soil_moisture_0_to_1cm", "cloud_cover"},
|
25 |
+
"daily": {"temperature_2m_max","precipitation_sum", "wind_speed_10m_max", "sunshine_duration", "rain_sum"},
|
26 |
+
"past_days" : 5,
|
27 |
+
"forecast_days" : 7
|
28 |
+
|
29 |
+
}
|
|
|
30 |
responses = openmeteo.weather_api(url, params=params)
|
31 |
response = responses[0]
|
32 |
|
33 |
+
#Hourly dataframe
|
34 |
+
|
35 |
hourly = response.Hourly()
|
36 |
hourly_relative_humidity_2m = hourly.Variables(0).ValuesAsNumpy()
|
37 |
hourly_soil_temperature_0cm = hourly.Variables(1).ValuesAsNumpy()
|
38 |
hourly_soil_moisture_0_to_1cm = hourly.Variables(2).ValuesAsNumpy()
|
39 |
+
hourly_cloud_cover = hourly.Variables(3).ValuesAsNumpy()
|
40 |
|
41 |
hourly_data = {"date": pd.date_range(
|
42 |
+
start = pd.to_datetime(hourly.Time(), unit = "s", utc = True),
|
43 |
+
end = pd.to_datetime(hourly.TimeEnd(), unit = "s", utc = True),
|
44 |
+
freq = pd.Timedelta(seconds = hourly.Interval()),
|
45 |
+
inclusive = "left"
|
46 |
)}
|
47 |
|
48 |
hourly_data["relative_humidity_2m_%"] = hourly_relative_humidity_2m
|
49 |
hourly_data["soil_temperature_0cm_C"] = hourly_soil_temperature_0cm
|
50 |
hourly_data["soil_moisture_0_to_1cm_m³"] = hourly_soil_moisture_0_to_1cm
|
51 |
+
hourly_data["cloud_cover_%"] = hourly_cloud_cover
|
52 |
|
53 |
+
hourly_dataframe = pd.DataFrame(data = hourly_data)
|
54 |
|
|
|
|
|
|
|
55 |
|
56 |
+
hourly_dataframe = pd.DataFrame(data = hourly_data)
|
|
|
57 |
|
58 |
+
#Average hourly data per day
|
59 |
+
hourly_dataframe['day_date'] = hourly_dataframe['date'].dt.strftime('%Y-%m-%d')
|
60 |
|
61 |
+
tmp1 = hourly_dataframe.groupby('day_date')[['relative_humidity_2m_%', 'soil_temperature_0cm_C', 'soil_moisture_0_to_1cm_m³']].mean()
|
62 |
+
|
63 |
+
avg_hourly_dataframe = tmp1.rename(columns={'relative_humidity_2m_%': 'avg_hourly_relative_humidity_2m_%', 'soil_temperature_0cm_C': 'avg_hourly_soil_temperature_0cm_C', 'soil_moisture_0_to_1cm_m³': 'avg_hourly_soil_moisture_0_to_1cm_m³'})
|
64 |
+
|
65 |
+
#med cloud couverture
|
66 |
+
tmp2 = hourly_dataframe.groupby('day_date')[['cloud_cover_%']].median()
|
67 |
+
|
68 |
+
med_cloud_cover = tmp2.rename(columns={'cloud_cover_%': 'med_cloud_cover_%'})
|
69 |
+
|
70 |
+
#Daily dataframe
|
71 |
daily = response.Daily()
|
72 |
daily_temperature_2m_max = daily.Variables(0).ValuesAsNumpy()
|
73 |
daily_precipitation_sum = daily.Variables(1).ValuesAsNumpy()
|
74 |
daily_wind_speed_10m_max = daily.Variables(2).ValuesAsNumpy()
|
75 |
daily_sunshine_duration = daily.Variables(3).ValuesAsNumpy()
|
76 |
+
daily_rain_sum = daily.Variables(4).ValuesAsNumpy()
|
77 |
|
78 |
daily_data = {"date": pd.date_range(
|
79 |
start=pd.to_datetime(daily.Time(), unit="s", utc=True),
|
80 |
end=pd.to_datetime(daily.TimeEnd(), unit="s", utc=True),
|
81 |
+
freq='D',
|
82 |
inclusive="left"
|
83 |
)}
|
84 |
|
|
|
86 |
daily_data["daily_precipitation_sum_mm"] = daily_precipitation_sum
|
87 |
daily_data["daily_wind_speed_10m_max_km/h"] = daily_wind_speed_10m_max
|
88 |
daily_data["daily_sunshine_duration_sec"] = daily_sunshine_duration
|
89 |
+
daily_data["daily_rain_sum_mm"] = daily_rain_sum
|
90 |
|
91 |
daily_dataframe = pd.DataFrame(data=daily_data)
|
92 |
|
93 |
+
daily_dataframe['day_date'] = daily_dataframe['date'].dt.strftime('%Y-%m-%d')
|
94 |
+
|
95 |
+
total_df = pd.merge(daily_dataframe, avg_hourly_dataframe, on="day_date", how="left")
|
96 |
+
total_df = pd.merge(total_df, med_cloud_cover, on="day_date", how="left")
|
97 |
|
98 |
total_df['date'] = total_df['day_date']
|
99 |
total_df = total_df.drop('day_date', axis=1)
|
100 |
+
|
101 |
return total_df
|
102 |
+
#total_df.to_json("weather_data.json", orient='columns')
|
app.py
CHANGED
@@ -5,9 +5,18 @@ from utils import *
|
|
5 |
with gr.Blocks() as demo:
|
6 |
temperature = gr.Number(visible=False)
|
7 |
humidite = gr.Number(visible=False)
|
8 |
-
|
|
|
|
|
9 |
gr.Markdown(
|
10 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
with gr.Row(equal_height=True):
|
12 |
with gr.Column():
|
13 |
with gr.Tab("Adresse"):
|
@@ -44,10 +53,12 @@ with gr.Blocks() as demo:
|
|
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], [
|
48 |
-
|
|
|
|
|
49 |
msg.submit(respond, [type_elevage, temperature,
|
50 |
-
humidite,
|
51 |
|
52 |
demo.title = "Démo GAIA - Les 5 Mousquetaires"
|
53 |
demo.launch()
|
|
|
5 |
with gr.Blocks() as demo:
|
6 |
temperature = gr.Number(visible=False)
|
7 |
humidite = gr.Number(visible=False)
|
8 |
+
chutes_de_neige = gr.Number(value=0, visible=False)
|
9 |
+
couverture_nuageuse = gr.Number(visible=False)
|
10 |
+
precipitations = gr.Number(visible=False)
|
11 |
gr.Markdown(
|
12 |
+
"""
|
13 |
+
## GAIA Démo \n
|
14 |
+
Démo avec Mistral AI & LlamaIndex afin d'estimer les risques parasitaires d'un élevage. \n
|
15 |
+
### Fonctionnement:
|
16 |
+
1. Rentrez votre adresse (ou les coordonnées GPS) de votre exploitation
|
17 |
+
2. Cochez votre type d'élevage
|
18 |
+
3. Posez la question liée aux risques parasitaires de votre exploitation (idée: 'Quels sont les risques')
|
19 |
+
4. Amusez vous à parcourir la carte et les données météo associées.""")
|
20 |
with gr.Row(equal_height=True):
|
21 |
with gr.Column():
|
22 |
with gr.Tab("Adresse"):
|
|
|
53 |
placeholder="Vous pouvez me poser une question, appuyez sur Entrée pour valider")
|
54 |
clear = gr.ClearButton([msg, chatbot])
|
55 |
|
56 |
+
demo.load(on_init, [lat, lon, address], [
|
57 |
+
map, fig, temperature, humidite, couverture_nuageuse, precipitations])
|
58 |
+
btn.click(on_init, [lat, lon, address], [
|
59 |
+
map, fig, temperature, humidite, couverture_nuageuse, precipitations])
|
60 |
msg.submit(respond, [type_elevage, temperature,
|
61 |
+
humidite, chutes_de_neige, couverture_nuageuse, precipitations, msg, chatbot], [msg, chatbot])
|
62 |
|
63 |
demo.title = "Démo GAIA - Les 5 Mousquetaires"
|
64 |
demo.launch()
|
utils.py
CHANGED
@@ -15,7 +15,7 @@ from llama_index.core.query_engine import RetrieverQueryEngine
|
|
15 |
load_dotenv()
|
16 |
|
17 |
Settings.llm = MistralAI(
|
18 |
-
max_tokens=
|
19 |
api_key=os.environ.get('MISTRAL_API_KEY')
|
20 |
)
|
21 |
|
@@ -35,9 +35,12 @@ def on_init(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):
|
@@ -48,14 +51,16 @@ def print_conversation(chat_history):
|
|
48 |
print(response, end='\n')
|
49 |
|
50 |
|
51 |
-
def respond(elevage, temperature, humidite,
|
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 |
-
-
|
|
|
|
|
59 |
|
60 |
Fais moi un tableau avec chaque parasite et/ou tiques susceptible de toucher mon élevage dans ces conditions météo, avec les conditions de prolifération, la vitesse de propagation, les troubles causés par ces parasites
|
61 |
Essaie d'écrire des données numériques précises dans le tableau
|
|
|
15 |
load_dotenv()
|
16 |
|
17 |
Settings.llm = MistralAI(
|
18 |
+
max_tokens=2048,
|
19 |
api_key=os.environ.get('MISTRAL_API_KEY')
|
20 |
)
|
21 |
|
|
|
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 |
+
#avg_snowfall = df.loc[:, 'daily_precipitation_sum_mm'].mean()
|
39 |
+
avg_cloud_cover = df.loc[:, 'med_cloud_cover_%'].mean()
|
40 |
+
avg_precipitations = df.loc[:, 'daily_rain_sum_mm'].mean()
|
41 |
|
42 |
print('toto')
|
43 |
+
return map_html, fig, avg_temp, avg_humidity, avg_cloud_cover, avg_precipitations
|
44 |
|
45 |
|
46 |
def print_conversation(chat_history):
|
|
|
51 |
print(response, end='\n')
|
52 |
|
53 |
|
54 |
+
def respond(elevage, temperature, humidite, chutes_de_neige, couverture_nuageuse, precipitations, message, chat_history):
|
55 |
PROMPT = f"""
|
56 |
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.
|
57 |
Voici les conditions:
|
58 |
- élevage: {elevage}
|
59 |
+
- température moyenne : {temperature} °C
|
60 |
+
- humidité moyenne : {humidite} %
|
61 |
+
- chutes de neige : {chutes_de_neige} cm
|
62 |
+
- couverture nuageuse : {couverture_nuageuse} %
|
63 |
+
- precipitations : {precipitations} mm
|
64 |
|
65 |
Fais moi un tableau avec chaque parasite et/ou tiques susceptible de toucher mon élevage dans ces conditions météo, avec les conditions de prolifération, la vitesse de propagation, les troubles causés par ces parasites
|
66 |
Essaie d'écrire des données numériques précises dans le tableau
|