Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -149,54 +149,55 @@ def get_soil_properties():
|
|
149 |
except Exception as e:
|
150 |
return jsonify({"error": str(e)}), 500
|
151 |
|
|
|
152 |
def call_gemini_api(input_data):
|
153 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
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')})
|
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 |
-
-
|
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
|
169 |
-
9.
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
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",
|
199 |
-
contents=prompt,
|
200 |
)
|
201 |
return response.text
|
202 |
|
@@ -204,130 +205,55 @@ Please provide the complete report in {language} language only.
|
|
204 |
@app.route('/predict', methods=['POST'])
|
205 |
def predict():
|
206 |
form_data = request.form.to_dict()
|
207 |
-
report_md = call_gemini_api(form_data)
|
208 |
-
|
209 |
-
# Convert raw markdown to HTML
|
210 |
-
report_html = markdown.markdown(report_md)
|
211 |
-
|
212 |
-
# Inject advanced, colorful styling into the final HTML
|
213 |
-
html_output = f"""<!DOCTYPE html>
|
214 |
-
<html lang="en">
|
215 |
-
<head>
|
216 |
-
<meta charset="UTF-8">
|
217 |
-
<title>Pest Outbreak Dashboard Report</title>
|
218 |
-
<!-- Tailwind for utility classes -->
|
219 |
-
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/tailwind.min.css" rel="stylesheet">
|
220 |
-
<style>
|
221 |
-
/* Overall page background with a subtle gradient */
|
222 |
-
body {{
|
223 |
-
margin: 0;
|
224 |
-
padding: 2rem;
|
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;
|
231 |
-
background-color: #ffffff;
|
232 |
-
border-radius: 8px;
|
233 |
-
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
|
234 |
-
padding: 2rem;
|
235 |
-
transition: transform 0.3s ease, box-shadow 0.3s ease;
|
236 |
-
}}
|
237 |
-
.report-container:hover {{
|
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;
|
244 |
-
font-size: 2rem;
|
245 |
-
margin-bottom: 1.5rem;
|
246 |
-
color: #ffffff;
|
247 |
-
background: linear-gradient(to right, #81c784, #388e3c);
|
248 |
-
padding: 1rem;
|
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 {{
|
255 |
-
margin-top: 1.5rem;
|
256 |
-
margin-bottom: 0.75rem;
|
257 |
color: #2c3e50;
|
258 |
text-align: left;
|
259 |
}}
|
|
|
260 |
/* Paragraphs */
|
261 |
.report-container p {{
|
262 |
margin-bottom: 1rem;
|
263 |
-
color: #555555;
|
264 |
text-align: justify;
|
265 |
line-height: 1.6;
|
266 |
}}
|
|
|
267 |
/* Lists */
|
268 |
.report-container ul,
|
269 |
.report-container ol {{
|
270 |
-
margin-left: 1.5rem;
|
271 |
margin-bottom: 1rem;
|
272 |
color: #555555;
|
273 |
}}
|
|
|
274 |
/* Table styling */
|
275 |
.report-container table {{
|
276 |
width: 100%;
|
277 |
-
border-collapse: collapse;
|
278 |
-
margin: 1.5rem 0;
|
279 |
-
}}
|
280 |
-
.report-container thead tr {{
|
281 |
-
background: linear-gradient(to right, #81c784, #388e3c);
|
282 |
-
color: #ffffff;
|
283 |
-
}}
|
284 |
-
.report-container th,
|
285 |
-
.report-container td {{
|
286 |
-
border: 1px solid #ddd;
|
287 |
-
padding: 12px 15px;
|
288 |
-
text-align: left;
|
289 |
-
transition: background-color 0.2s ease;
|
290 |
-
}}
|
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,
|
297 |
-
.report-container thead,
|
298 |
-
.report-container tbody,
|
299 |
-
.report-container th,
|
300 |
-
.report-container td,
|
301 |
-
.report-container tr {{
|
302 |
-
display: block;
|
303 |
-
width: 100%;
|
304 |
-
}}
|
305 |
-
.report-container thead tr {{
|
306 |
-
display: none;
|
307 |
-
}}
|
308 |
-
.report-container td {{
|
309 |
-
border: none;
|
310 |
-
border-bottom: 1px solid #ddd;
|
311 |
-
position: relative;
|
312 |
-
padding-left: 50%;
|
313 |
-
text-align: left;
|
314 |
-
}}
|
315 |
-
.report-container td:before {{
|
316 |
-
content: attr(data-label);
|
317 |
-
position: absolute;
|
318 |
-
left: 15px;
|
319 |
-
font-weight: bold;
|
320 |
-
}}
|
321 |
-
}}
|
322 |
-
</style>
|
323 |
-
</head>
|
324 |
-
<body>
|
325 |
-
<div class="report-container">
|
326 |
-
{report_html}
|
327 |
-
</div>
|
328 |
-
</body>
|
329 |
-
</html>"""
|
330 |
-
return Response(html_output, mimetype="text/html")
|
331 |
|
332 |
|
333 |
if __name__ == '__main__':
|
|
|
149 |
except Exception as e:
|
150 |
return jsonify({"error": str(e)}), 500
|
151 |
|
152 |
+
|
153 |
def call_gemini_api(input_data):
|
154 |
+
"""
|
155 |
+
Enhanced prompt: We request a visually appealing Markdown report WITHOUT
|
156 |
+
showing raw CSS code blocks. Instead, we want a descriptive layout.
|
157 |
+
|
158 |
+
NOTE: We instruct the model to produce headings, paragraphs, and a table
|
159 |
+
in a color-rich, well-spaced manner, but NOT to display raw CSS code.
|
160 |
+
"""
|
161 |
prompt = f"""
|
162 |
Create a visually appealing, farmer-friendly pest outbreak report in Markdown with the following:
|
163 |
+
|
164 |
1. A large, centered heading: "Pest Outbreak Dashboard Report".
|
165 |
+
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.
|
166 |
3. Several subheadings (e.g., "Agricultural Inputs", "Pest Outbreak Analysis", "Best Agricultural Practices", "Insights") with short paragraphs.
|
167 |
4. A colorfully styled table (no raw CSS code blocks) with:
|
168 |
- Pest Name
|
169 |
- Predicted Outbreak Month(s)
|
170 |
- Severity
|
171 |
+
- potential Damage by Pests
|
172 |
- Precautionary Measures against damages
|
173 |
+
5. Provide bullet points for best practices.
|
174 |
+
6. Use a friendly color scheme, with subtle hovers or highlights for rows, and consistent fonts.
|
175 |
+
7. Avoid printing any raw code blocks.
|
176 |
+
8. Incorporate the weather, soil, and agricultural data (like sowing date, irrigation method) into the narrative but do not list them as raw parameters.
|
177 |
+
9. do not give off topic insitruction only pest outbreka report i want okay, and dotn use special characters and justified text
|
178 |
+
Important details from the user:
|
179 |
+
- Crop Type: {input_data.get('crop_type')}
|
180 |
+
- Sowing Date: {input_data.get('sowing_date')}
|
181 |
+
- Harvest Date: {input_data.get('harvest_date')}
|
182 |
+
- Current Growth Stage: {input_data.get('growth_stage')}
|
183 |
+
- Irrigation Frequency: {input_data.get('irrigation_freq')}
|
184 |
+
- Irrigation Method: {input_data.get('irrigation_method')}
|
185 |
+
- Soil Type: {input_data.get('soil_type')}
|
186 |
+
|
187 |
+
- Max Temp: {input_data.get('max_temp')}
|
188 |
+
- Min Temp: {input_data.get('min_temp')}
|
189 |
+
- Current Temp: {input_data.get('current_temp')}
|
190 |
+
- Humidity: {input_data.get('humidity')}
|
191 |
+
- Rainfall: {input_data.get('rain')}
|
192 |
+
- Soil Moisture: {input_data.get('soil_moisture')}
|
193 |
+
- Wind Speed: {input_data.get('wind_speed')}
|
194 |
+
- Cloud Cover: {input_data.get('cloud_cover')}
|
195 |
+
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
|
196 |
+
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
|
197 |
+
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
|
|
|
|
|
|
|
|
|
|
|
|
|
198 |
"""
|
199 |
response = client.models.generate_content(
|
200 |
model="gemini-2.0-flash",
|
|
|
201 |
)
|
202 |
return response.text
|
203 |
|
|
|
205 |
@app.route('/predict', methods=['POST'])
|
206 |
def predict():
|
207 |
form_data = request.form.to_dict()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
208 |
background: linear-gradient(120deg, #f7f7f7 0%, #e3f2fd 100%);
|
209 |
font-family: 'Segoe UI', Tahoma, sans-serif;
|
210 |
}}
|
211 |
+
|
212 |
.report-container {{
|
213 |
max-width: 1000px;
|
214 |
margin: 0 auto;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
215 |
transform: translateY(-4px);
|
216 |
box-shadow: 0 12px 24px rgba(0,0,0,0.15);
|
217 |
}}
|
218 |
+
|
219 |
/* Gradient heading for H1 */
|
220 |
.report-container h1 {{
|
221 |
text-align: center;
|
|
|
|
|
|
|
|
|
|
|
222 |
border-radius: 6px;
|
223 |
box-shadow: inset 0 1px 2px rgba(0,0,0,0.1);
|
224 |
}}
|
225 |
+
|
226 |
/* Secondary headings (H2, H3) */
|
227 |
.report-container h2,
|
228 |
.report-container h3 {{
|
|
|
|
|
229 |
color: #2c3e50;
|
230 |
text-align: left;
|
231 |
}}
|
232 |
+
|
233 |
/* Paragraphs */
|
234 |
.report-container p {{
|
235 |
margin-bottom: 1rem;
|
|
|
236 |
text-align: justify;
|
237 |
line-height: 1.6;
|
238 |
}}
|
239 |
+
|
240 |
/* Lists */
|
241 |
.report-container ul,
|
242 |
.report-container ol {{
|
|
|
243 |
margin-bottom: 1rem;
|
244 |
color: #555555;
|
245 |
}}
|
246 |
+
|
247 |
/* Table styling */
|
248 |
.report-container table {{
|
249 |
width: 100%;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
250 |
.report-container tbody tr:hover {{
|
251 |
background-color: #f9f9f9;
|
252 |
}}
|
253 |
+
|
254 |
/* Responsive table for smaller screens */
|
255 |
@media (max-width: 768px) {{
|
256 |
.report-container table,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
257 |
|
258 |
|
259 |
if __name__ == '__main__':
|