rajkhanke commited on
Commit
15dc575
·
verified ·
1 Parent(s): 8b83ec0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -43
app.py CHANGED
@@ -150,50 +150,49 @@ def get_soil_properties():
150
  return jsonify({"error": str(e)}), 500
151
 
152
  def call_gemini_api(input_data):
153
- """
154
- Enhanced prompt: We request a visually appealing Markdown report WITHOUT
155
- showing raw CSS code blocks. Instead, we want a descriptive layout.
156
-
157
- NOTE: We instruct the model to produce headings, paragraphs, and a table
158
- in a color-rich, well-spaced manner, but NOT to display raw CSS code.
159
- """
160
  prompt = f"""
161
  Create a visually appealing, farmer-friendly pest outbreak report in Markdown with the following:
162
-
163
  1. A large, centered heading: "Pest Outbreak Dashboard Report".
164
- 2. A short paragraph indicating location (latitude: {input_data.get('latitude')}, longitude: {input_data.get('longitude')}), location as per lat,long(like just ex dont consider it as hardoced nagpur,india so kike fetch from lat,long) and the crop/farm context.
165
  3. Several subheadings (e.g., "Agricultural Inputs", "Pest Outbreak Analysis", "Best Agricultural Practices", "Insights") with short paragraphs.
166
  4. A colorfully styled table (no raw CSS code blocks) with:
167
  - Pest Name
168
  - Predicted Outbreak Month(s)
169
  - Severity
170
- - potential Damage by Pests
171
  - Precautionary Measures against damages
172
- 5. Provide bullet points for best practices.
173
- 6. Use a friendly color scheme, with subtle hovers or highlights for rows, and consistent fonts.
174
- 7. Avoid printing any raw code blocks.
175
- 8. Incorporate the weather, soil, and agricultural data (like sowing date, irrigation method) into the narrative but do not list them as raw parameters.
176
- 9. do not give off topic insitruction only pest outbreka report i want okay, and dotn use special characters and justified text
177
- Important details from the user:
178
- - Crop Type: {input_data.get('crop_type')}
179
- - Sowing Date: {input_data.get('sowing_date')}
180
- - Harvest Date: {input_data.get('harvest_date')}
181
- - Current Growth Stage: {input_data.get('growth_stage')}
182
- - Irrigation Frequency: {input_data.get('irrigation_freq')}
183
- - Irrigation Method: {input_data.get('irrigation_method')}
184
- - Soil Type: {input_data.get('soil_type')}
185
-
186
- - Max Temp: {input_data.get('max_temp')}
187
- - Min Temp: {input_data.get('min_temp')}
188
- - Current Temp: {input_data.get('current_temp')}
189
- - Humidity: {input_data.get('humidity')}
190
- - Rainfall: {input_data.get('rain')}
191
- - Soil Moisture: {input_data.get('soil_moisture')}
192
- - Wind Speed: {input_data.get('wind_speed')}
193
- - Cloud Cover: {input_data.get('cloud_cover')}
194
- 10. also i want specific reocmmendation on pest control (seprate than precuatuonary measure below it in bullet pooints),best agriculktual practices,not generlaized one , but speicifc as perstudiyng each input paprmaetenrindetial okay,poepr sltying tbale should be rendered porpelry etc.. porper bold heaidng ,big fotn,left allgiemnd jsutified text
195
- 11.again order first title the lat,long,location derive form lat long(ex : nagpur,india) then below it agiruclturla oinput parmeter analysis, then pest tbale then pest avidnaces practice in dpeth 5-6 with bueet pint safter that spciific agrficulturla best practices as per input parameters, after more dept contnext this shoudl be order
196
- 12. i want short sentences and easily understandbale language for farmers big size font and colorful for subheadings , dont include paprmagrpash ,include short easily undertabsdbale senetences and contne tby farmers and porper ui in first run itself,for ui imorvement currently i have to rerun the modoel so tkae care of that, also hightlight important point sby yellow higlighters alll hihglighters pijtns should hihglihgt like key damages,reocmendations,pest,,key season like this.,also note that in first rnedering proepr well formatetd stlyed,wellr endered tbale s etc display and yellow hihglighters i want not yellow text,text is blakc highloght key poitns by yellow
 
 
 
 
 
 
197
  """
198
  response = client.models.generate_content(
199
  model="gemini-2.0-flash",
@@ -201,6 +200,7 @@ Important details from the user:
201
  )
202
  return response.text
203
 
 
204
  @app.route('/predict', methods=['POST'])
205
  def predict():
206
  form_data = request.form.to_dict()
@@ -225,7 +225,6 @@ def predict():
225
  background: linear-gradient(120deg, #f7f7f7 0%, #e3f2fd 100%);
226
  font-family: 'Segoe UI', Tahoma, sans-serif;
227
  }}
228
-
229
  .report-container {{
230
  max-width: 1000px;
231
  margin: 0 auto;
@@ -239,7 +238,6 @@ def predict():
239
  transform: translateY(-4px);
240
  box-shadow: 0 12px 24px rgba(0,0,0,0.15);
241
  }}
242
-
243
  /* Gradient heading for H1 */
244
  .report-container h1 {{
245
  text-align: center;
@@ -251,7 +249,6 @@ def predict():
251
  border-radius: 6px;
252
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.1);
253
  }}
254
-
255
  /* Secondary headings (H2, H3) */
256
  .report-container h2,
257
  .report-container h3 {{
@@ -260,7 +257,6 @@ def predict():
260
  color: #2c3e50;
261
  text-align: left;
262
  }}
263
-
264
  /* Paragraphs */
265
  .report-container p {{
266
  margin-bottom: 1rem;
@@ -268,7 +264,6 @@ def predict():
268
  text-align: justify;
269
  line-height: 1.6;
270
  }}
271
-
272
  /* Lists */
273
  .report-container ul,
274
  .report-container ol {{
@@ -276,7 +271,6 @@ def predict():
276
  margin-bottom: 1rem;
277
  color: #555555;
278
  }}
279
-
280
  /* Table styling */
281
  .report-container table {{
282
  width: 100%;
@@ -297,7 +291,6 @@ def predict():
297
  .report-container tbody tr:hover {{
298
  background-color: #f9f9f9;
299
  }}
300
-
301
  /* Responsive table for smaller screens */
302
  @media (max-width: 768px) {{
303
  .report-container table,
@@ -338,4 +331,4 @@ def predict():
338
 
339
 
340
  if __name__ == '__main__':
341
- app.run(debug=True)
 
150
  return jsonify({"error": str(e)}), 500
151
 
152
  def call_gemini_api(input_data):
153
+ language = input_data.get('language', 'English')
 
 
 
 
 
 
154
  prompt = f"""
155
  Create a visually appealing, farmer-friendly pest outbreak report in Markdown with the following:
 
156
  1. A large, centered heading: "Pest Outbreak Dashboard Report".
157
+ 2. A short paragraph indicating location (latitude: {input_data.get('latitude')}, longitude: {input_data.get('longitude')}) with the location derived from lat,long.
158
  3. Several subheadings (e.g., "Agricultural Inputs", "Pest Outbreak Analysis", "Best Agricultural Practices", "Insights") with short paragraphs.
159
  4. A colorfully styled table (no raw CSS code blocks) with:
160
  - Pest Name
161
  - Predicted Outbreak Month(s)
162
  - Severity
163
+ - Potential Damage by Pests
164
  - Precautionary Measures against damages
165
+ 5. Provide bullet points for best practices.
166
+ 6. Use a friendly color scheme with subtle hovers or highlights for rows, and consistent fonts.
167
+ 7. Avoid printing any raw code blocks.
168
+ 8. Incorporate the weather, soil, and agricultural data (like sowing date, irrigation method) into the narrative without listing them as raw parameters.
169
+ 9. Do not give off-topic instructions—only pest outbreak report instructions.
170
+ 10. Important details from the user:
171
+ - Crop Type: {input_data.get('crop_type')}
172
+ - Sowing Date: {input_data.get('sowing_date')}
173
+ - Harvest Date: {input_data.get('harvest_date')}
174
+ - Current Growth Stage: {input_data.get('growth_stage')}
175
+ - Irrigation Frequency: {input_data.get('irrigation_freq')}
176
+ - Irrigation Method: {input_data.get('irrigation_method')}
177
+ - Soil Type: {input_data.get('soil_type')}
178
+ - Max Temp: {input_data.get('max_temp')}
179
+ - Min Temp: {input_data.get('min_temp')}
180
+ - Current Temp: {input_data.get('current_temp')}
181
+ - Humidity: {input_data.get('humidity')}
182
+ - Rainfall: {input_data.get('rain')}
183
+ - Soil Moisture: {input_data.get('soil_moisture')}
184
+ - Wind Speed: {input_data.get('wind_speed')}
185
+ - Cloud Cover: {input_data.get('cloud_cover')}
186
+ 11. Order the content as follows:
187
+ - First, display the title along with the derived location (e.g., Nagpur, India).
188
+ - Next, show the agricultural input parameters analysis.
189
+ - Then, present the pest table.
190
+ - Followed by pest avoidance practices in-depth (5-6 bullet points).
191
+ - Finally, include specific agricultural best practices based on the inputs.
192
+ 12. Use short, easily understandable sentences suitable for farmers, with large fonts and colorful subheadings.
193
+ 13. Do not include long paragraphs; keep the language simple and the report well-formatted.
194
+ 14. Highlight important points (such as key damages, recommendations, pest names, key seasons) with yellow highlighters (only highlight key points, not the text).
195
+ Please provide the complete report in {language} language only.
196
  """
197
  response = client.models.generate_content(
198
  model="gemini-2.0-flash",
 
200
  )
201
  return response.text
202
 
203
+
204
  @app.route('/predict', methods=['POST'])
205
  def predict():
206
  form_data = request.form.to_dict()
 
225
  background: linear-gradient(120deg, #f7f7f7 0%, #e3f2fd 100%);
226
  font-family: 'Segoe UI', Tahoma, sans-serif;
227
  }}
 
228
  .report-container {{
229
  max-width: 1000px;
230
  margin: 0 auto;
 
238
  transform: translateY(-4px);
239
  box-shadow: 0 12px 24px rgba(0,0,0,0.15);
240
  }}
 
241
  /* Gradient heading for H1 */
242
  .report-container h1 {{
243
  text-align: center;
 
249
  border-radius: 6px;
250
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.1);
251
  }}
 
252
  /* Secondary headings (H2, H3) */
253
  .report-container h2,
254
  .report-container h3 {{
 
257
  color: #2c3e50;
258
  text-align: left;
259
  }}
 
260
  /* Paragraphs */
261
  .report-container p {{
262
  margin-bottom: 1rem;
 
264
  text-align: justify;
265
  line-height: 1.6;
266
  }}
 
267
  /* Lists */
268
  .report-container ul,
269
  .report-container ol {{
 
271
  margin-bottom: 1rem;
272
  color: #555555;
273
  }}
 
274
  /* Table styling */
275
  .report-container table {{
276
  width: 100%;
 
291
  .report-container tbody tr:hover {{
292
  background-color: #f9f9f9;
293
  }}
 
294
  /* Responsive table for smaller screens */
295
  @media (max-width: 768px) {{
296
  .report-container table,
 
331
 
332
 
333
  if __name__ == '__main__':
334
+ app.run(debug=True)