Spaces:
Sleeping
Sleeping
robgenesis
commited on
Structure of model query
Browse files
app.py
CHANGED
@@ -15,8 +15,8 @@ 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 = "
|
19 |
-
description = "
|
20 |
placeholder = (
|
21 |
"Vous pouvez me posez une question sur ce contexte, appuyer sur Entrée pour valider"
|
22 |
)
|
@@ -50,6 +50,31 @@ index = VectorStoreIndex(
|
|
50 |
query_engine = index.as_query_engine(similarity_top_k=5)
|
51 |
|
52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
# Structure of the data sent by the form
|
54 |
InputForm = typing_extensions.TypedDict('InputForm', {
|
55 |
'department': str,
|
@@ -61,7 +86,13 @@ InputForm = typing_extensions.TypedDict('InputForm', {
|
|
61 |
|
62 |
# This function is the API endpoint the web app will use
|
63 |
def find_my_rotation(department: str, farmSize: float, benefitsFromCommonAgriculturalPolicy: bool, cultures: list[str], yields: dict[str, float]):
|
64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
|
66 |
|
67 |
def get_documents_in_db():
|
@@ -113,7 +144,6 @@ with gr.Blocks() as demo:
|
|
113 |
Add a file before interacting with the Chat.
|
114 |
This demo allows you to interact with a pdf file and then ask questions to Mistral APIs.
|
115 |
Mistral will answer with the context extracted from your uploaded file.
|
116 |
-
|
117 |
*The files will stay in the database unless there is 48h of inactivty or you re-build the space.*
|
118 |
"""
|
119 |
)
|
@@ -186,4 +216,4 @@ with gr.Blocks() as demo:
|
|
186 |
|
187 |
demo.title = title
|
188 |
|
189 |
-
demo.launch()
|
|
|
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"
|
20 |
placeholder = (
|
21 |
"Vous pouvez me posez une question sur ce contexte, appuyer sur Entrée pour valider"
|
22 |
)
|
|
|
50 |
query_engine = index.as_query_engine(similarity_top_k=5)
|
51 |
|
52 |
|
53 |
+
def load_local_data(data_folder):
|
54 |
+
|
55 |
+
ids = chroma_collection.get()["ids"]
|
56 |
+
chroma_collection.delete(ids)
|
57 |
+
print('Cleaning DB')
|
58 |
+
|
59 |
+
for file in os.listdir(data_folder):
|
60 |
+
print('Adding file ' + file + ' to DB')
|
61 |
+
documents = loader.load_data(file= data_folder + file)
|
62 |
+
|
63 |
+
for doc in documents:
|
64 |
+
index.insert(doc)
|
65 |
+
|
66 |
+
|
67 |
+
def create_prompt(farmSize, cultures):
|
68 |
+
prompt = f"""
|
69 |
+
You are an agronomical advisor. Your task is to provide an advice to the farmer what to seed in the next year and in which proportion. You will be given the historical information about the farmer. Consider agronomical limitation and provide advice to the farmer to maximize his profit (maximum yield and price)
|
70 |
+
#facts
|
71 |
+
The farm area is {farmSize} ha.
|
72 |
+
"""
|
73 |
+
for i, culture in enumerate(cultures):
|
74 |
+
prompt += f"Parcel {i} most recently grew {culture}."
|
75 |
+
return prompt
|
76 |
+
|
77 |
+
|
78 |
# Structure of the data sent by the form
|
79 |
InputForm = typing_extensions.TypedDict('InputForm', {
|
80 |
'department': str,
|
|
|
86 |
|
87 |
# This function is the API endpoint the web app will use
|
88 |
def find_my_rotation(department: str, farmSize: float, benefitsFromCommonAgriculturalPolicy: bool, cultures: list[str], yields: dict[str, float]):
|
89 |
+
# Load data into the context
|
90 |
+
load_local_data("./data/departments")
|
91 |
+
# Create the prompt
|
92 |
+
prompt = create_prompt(farmSize, cultures)
|
93 |
+
# Question the model
|
94 |
+
response = query_engine.query(prompt)
|
95 |
+
return response
|
96 |
|
97 |
|
98 |
def get_documents_in_db():
|
|
|
144 |
Add a file before interacting with the Chat.
|
145 |
This demo allows you to interact with a pdf file and then ask questions to Mistral APIs.
|
146 |
Mistral will answer with the context extracted from your uploaded file.
|
|
|
147 |
*The files will stay in the database unless there is 48h of inactivty or you re-build the space.*
|
148 |
"""
|
149 |
)
|
|
|
216 |
|
217 |
demo.title = title
|
218 |
|
219 |
+
demo.launch()
|