Spaces:
Runtime error
Runtime error
Achille Thin - Genesis
commited on
Commit
·
bbd44b8
1
Parent(s):
1771168
adding department specifics
Browse files
app.py
CHANGED
@@ -14,6 +14,7 @@ from llama_index.embeddings import MistralAIEmbedding
|
|
14 |
from llama_index.vector_stores import ChromaVectorStore
|
15 |
from llama_index.storage.storage_context import StorageContext
|
16 |
from llama_index import ServiceContext
|
|
|
17 |
|
18 |
title = "Team LFD rotation finder app"
|
19 |
description = "Propose a rotation for a farmer"
|
@@ -51,7 +52,7 @@ query_engine = index.as_query_engine(similarity_top_k=10)
|
|
51 |
|
52 |
def create_prompt(farmSize, cultures):
|
53 |
prompt = f"""
|
54 |
-
You are a French agronomical advisor, answering in French. Your task is to provide an concise advice as a table of rotation crops (with a prioritary suggestion and an alternative one) to the farmer what to seed in the next year and in which proportion. You will be given the historical information about the farmer, and context data given previously gives you average performances in yield per acre by region and by culture, as well as production costs and selling prices. Consider agronomical limitation and provide advice to the farmer to maximize his profit (maximum yield and revenue -- the difference between the selling price and the cost of production). There are three possible scenarii, pessimistic (lowest revenue), optimistic (highest revenue) and mean.
|
55 |
#facts
|
56 |
The farm area is {farmSize} ha.
|
57 |
"""
|
@@ -74,8 +75,13 @@ InputForm = typing_extensions.TypedDict('InputForm', {
|
|
74 |
|
75 |
# This function is the API endpoint the web app will use
|
76 |
def find_my_rotation(department: str, farmSize: float, benefitsFromCommonAgriculturalPolicy: bool, cultures: list[str], yields: dict[str, float]):
|
77 |
-
|
|
|
|
|
|
|
|
|
78 |
# Create the prompt
|
|
|
79 |
prompt = create_prompt(farmSize, cultures)
|
80 |
# Question the model
|
81 |
response = query_engine.query(prompt)
|
|
|
14 |
from llama_index.vector_stores import ChromaVectorStore
|
15 |
from llama_index.storage.storage_context import StorageContext
|
16 |
from llama_index import ServiceContext
|
17 |
+
from utils import departments_list, region_list
|
18 |
|
19 |
title = "Team LFD rotation finder app"
|
20 |
description = "Propose a rotation for a farmer"
|
|
|
52 |
|
53 |
def create_prompt(farmSize, cultures):
|
54 |
prompt = f"""
|
55 |
+
You are a French agronomical advisor, answering in French. Your task is to provide an concise advice as a table of rotation crops (with a prioritary suggestion and an alternative one) to the farmer what to seed in the next year and in which proportion. You will be given the historical information about the farmer, and context data given previously gives you average performances in yield per acre by region and by culture, as well as production costs and selling prices. Consider agronomical limitation and provide advice to the farmer to maximize his profit (maximum yield and revenue -- (the difference between the selling price and the cost of production) times the yield). There are three possible scenarii, pessimistic (lowest revenue), optimistic (highest revenue) and mean.
|
56 |
#facts
|
57 |
The farm area is {farmSize} ha.
|
58 |
"""
|
|
|
75 |
|
76 |
# This function is the API endpoint the web app will use
|
77 |
def find_my_rotation(department: str, farmSize: float, benefitsFromCommonAgriculturalPolicy: bool, cultures: list[str], yields: dict[str, float]):
|
78 |
+
department_name = departments_list.get(department)
|
79 |
+
dpt_yield = pd.read_csv(f'data/departments/{department_name}.csv')
|
80 |
+
yield_text = ''
|
81 |
+
for i, _ in dpt_yield:
|
82 |
+
yield_text += f"Dans le département de {department_name}, la production de {dpt_yield['Culture'][i].split('-')[1]} est de {dpt_yield['mean'][i]} en moyenne, de {dpt_yield['pessimistic'][i]} avec un scenario pessimiste et de {dpt_yield['optimistic'][i]} avec un scenario optimiste"
|
83 |
# Create the prompt
|
84 |
+
index.insert(Document(text=yield_text))
|
85 |
prompt = create_prompt(farmSize, cultures)
|
86 |
# Question the model
|
87 |
response = query_engine.query(prompt)
|