Spaces:
Sleeping
Sleeping
Adding possible question generator
Browse files
utils.py
ADDED
@@ -0,0 +1,163 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
|
3 |
+
region_list = {
|
4 |
+
'Auvergne-Rhône-Alpes': ['01', '03', '07', '15', '26', '38', '42', '43', '63', '69', '73', '74'],
|
5 |
+
'Bourgogne-Franche-Comté': ['21', '25', '39', '58', '70', '71', '89', '90'],
|
6 |
+
'Bretagne': ['35', '22', '56', '29'],
|
7 |
+
'Centre-Val de Loire': ['18', '28', '36', '37', '41', '45'],
|
8 |
+
'Corse': ['2A', '2B'],
|
9 |
+
'Grand Est': ['08', '10', '51', '52', '54', '55', '57', '67', '68', '88'],
|
10 |
+
'Guadeloupe': ['971'],
|
11 |
+
'Guyane': ['973'],
|
12 |
+
'Hauts-de-France': ['02', '59', '60', '62', '80'],
|
13 |
+
'Île-de-France': ['75', '77', '78', '91', '92', '93', '94', '95'],
|
14 |
+
'La Réunion': ['974'],
|
15 |
+
'Martinique': ['972'],
|
16 |
+
'Normandie': ['14', '27', '50', '61', '76'],
|
17 |
+
'Nouvelle-Aquitaine': ['16', '17', '19', '23', '24', '33', '40', '47', '64', '79', '86', '87'],
|
18 |
+
'Occitanie': ['09', '11', '12', '30', '31', '32', '34', '46', '48', '65', '66', '81', '82'],
|
19 |
+
'Pays de la Loire': ['44', '49', '53', '72', '85'],
|
20 |
+
'Provence-Alpes-Côte d\'Azur': ['04', '05', '06', '13', '83', '84'],
|
21 |
+
}
|
22 |
+
|
23 |
+
departments_list = {
|
24 |
+
'01': 'Ain',
|
25 |
+
'02': 'Aisne',
|
26 |
+
'03': 'Allier',
|
27 |
+
'04': 'Alpes-de-Haute-Provence',
|
28 |
+
'05': 'Hautes-Alpes',
|
29 |
+
'06': 'Alpes-Maritimes',
|
30 |
+
'07': 'Ardèche',
|
31 |
+
'08': 'Ardennes',
|
32 |
+
'09': 'Ariège',
|
33 |
+
'10': 'Aube',
|
34 |
+
'11': 'Aude',
|
35 |
+
'12': 'Aveyron',
|
36 |
+
'13': 'Bouches-du-Rhône',
|
37 |
+
'14': 'Calvados',
|
38 |
+
'15': 'Cantal',
|
39 |
+
'16': 'Charente',
|
40 |
+
'17': 'Charente-Maritime',
|
41 |
+
'18': 'Cher',
|
42 |
+
'19': 'Corrèze',
|
43 |
+
'2A': 'Corse-du-Sud',
|
44 |
+
'2B': 'Haute-Corse',
|
45 |
+
'21': 'Côte-d\'Or',
|
46 |
+
'22': 'Côtes-d\'Armor',
|
47 |
+
'23': 'Creuse',
|
48 |
+
'24': 'Dordogne',
|
49 |
+
'25': 'Doubs',
|
50 |
+
'26': 'Drôme',
|
51 |
+
'27': 'Eure',
|
52 |
+
'28': 'Eure-et-Loir',
|
53 |
+
'29': 'Finistère',
|
54 |
+
'30': 'Gard',
|
55 |
+
'31': 'Haute-Garonne',
|
56 |
+
'32': 'Gers',
|
57 |
+
'33': 'Gironde',
|
58 |
+
'34': 'Hérault',
|
59 |
+
'35': 'Ille-et-Vilaine',
|
60 |
+
'36': 'Indre',
|
61 |
+
'37': 'Indre-et-Loire',
|
62 |
+
'38': 'Isère',
|
63 |
+
'39': 'Jura',
|
64 |
+
'40': 'Landes',
|
65 |
+
'41': 'Loir-et-Cher',
|
66 |
+
'42': 'Loire',
|
67 |
+
'43': 'Haute-Loire',
|
68 |
+
'44': 'Loire-Atlantique',
|
69 |
+
'45': 'Loiret',
|
70 |
+
'46': 'Lot',
|
71 |
+
'47': 'Lot-et-Garonne',
|
72 |
+
'48': 'Lozère',
|
73 |
+
'49': 'Maine-et-Loire',
|
74 |
+
'50': 'Manche',
|
75 |
+
'51': 'Marne',
|
76 |
+
'52': 'Haute-Marne',
|
77 |
+
'53': 'Mayenne',
|
78 |
+
'54': 'Meurthe-et-Moselle',
|
79 |
+
'55': 'Meuse',
|
80 |
+
'56': 'Morbihan',
|
81 |
+
'57': 'Moselle',
|
82 |
+
'58': 'Nièvre',
|
83 |
+
'59': 'Nord',
|
84 |
+
'60': 'Oise',
|
85 |
+
'61': 'Orne',
|
86 |
+
'62': 'Pas-de-Calais',
|
87 |
+
'63': 'Puy-de-Dôme',
|
88 |
+
'64': 'Pyrénées-Atlantiques',
|
89 |
+
'65': 'Hautes-Pyrénées',
|
90 |
+
'66': 'Pyrénées-Orientales',
|
91 |
+
'67': 'Bas-Rhin',
|
92 |
+
'68': 'Haut-Rhin',
|
93 |
+
'69': 'Rhône',
|
94 |
+
'70': 'Haute-Saône',
|
95 |
+
'71': 'Saône-et-Loire',
|
96 |
+
'72': 'Sarthe',
|
97 |
+
'73': 'Savoie',
|
98 |
+
'74': 'Haute-Savoie',
|
99 |
+
'75': 'Paris',
|
100 |
+
'76': 'Seine-Maritime',
|
101 |
+
'77': 'Seine-et-Marne',
|
102 |
+
'78': 'Yvelines',
|
103 |
+
'79': 'Deux-Sèvres',
|
104 |
+
'80': 'Somme',
|
105 |
+
'81': 'Tarn',
|
106 |
+
'82': 'Tarn-et-Garonne',
|
107 |
+
'83': 'Var',
|
108 |
+
'84': 'Vaucluse',
|
109 |
+
'85': 'Vendée',
|
110 |
+
'86': 'Vienne',
|
111 |
+
'87': 'Haute-Vienne',
|
112 |
+
'88': 'Vosges',
|
113 |
+
'89': 'Yonne',
|
114 |
+
'90': 'Territoire de Belfort',
|
115 |
+
'91': 'Essonne',
|
116 |
+
'92': 'Hauts-de-Seine',
|
117 |
+
'93': 'Seine-Saint-Denis',
|
118 |
+
'94': 'Val-de-Marne',
|
119 |
+
'95': 'Val-d\'Oise',
|
120 |
+
'971': 'Guadeloupe',
|
121 |
+
'972': 'Martinique',
|
122 |
+
'973': 'Guyane',
|
123 |
+
'974': 'La Réunion',
|
124 |
+
'976': 'Mayotte',
|
125 |
+
}
|
126 |
+
|
127 |
+
json_data = '''
|
128 |
+
{
|
129 |
+
"department": "10",
|
130 |
+
"farmSize": 200,
|
131 |
+
"benefitsFromCommonAgriculturalPolicy": true,
|
132 |
+
"cultures": ["Blé", "Colza", "Carottes"],
|
133 |
+
"yields": {"Blé": 50, "Colza": 150, "Carottes": 11}
|
134 |
+
}
|
135 |
+
'''
|
136 |
+
def generate_question(json_data):
|
137 |
+
data = json.loads(json_data)
|
138 |
+
|
139 |
+
department_number = data['department']
|
140 |
+
farm_size = data['farmSize']
|
141 |
+
benefits_from_common_agricultural_policy = data['benefitsFromCommonAgriculturalPolicy']
|
142 |
+
cultures = data['cultures']
|
143 |
+
yields = data['yields']
|
144 |
+
|
145 |
+
department_name = departments_list.get(department_number)
|
146 |
+
number_fields = str(len(yields))
|
147 |
+
|
148 |
+
for region, department_codes in region_list.items():
|
149 |
+
if department_number in department_codes:
|
150 |
+
region_name = region
|
151 |
+
|
152 |
+
question = '''You are an agronomical advisor. Your task is to provide an advice to the farmer what to seed in the next year and for each field in a table format. You will be given the historical information about the farmer. Consider agronomical limitations, maximize his profit for 2024 based on the price information, avoid the repetition of the crop from 2023 for the same field and give a justification
|
153 |
+
#facts
|
154 |
+
The farmer is located in the region Charente-Maritime, departament ''' + department_name + ''' in region ''' + region_name
|
155 |
+
'''The farm area is ''' + str(farm_size) + '''
|
156 |
+
It has ''' + number_fields +''' fields '''
|
157 |
+
|
158 |
+
|
159 |
+
print(question)
|
160 |
+
for field_number, (crop, yield_value) in enumerate(yields.items(), start=1):
|
161 |
+
print(f"Field {field_number} in 2023 was seeded with {crop} with a yield of {yield_value}.")
|
162 |
+
|
163 |
+
generate_question(json_data)
|