Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -36,6 +36,7 @@ def get_weather_data():
|
|
36 |
lat, lon = validate_coordinates(lat, lon)
|
37 |
if lat is None or lon is None:
|
38 |
return jsonify({"error": "Invalid coordinates"}), 400
|
|
|
39 |
|
40 |
try:
|
41 |
forecast_url = "https://api.open-meteo.com/v1/forecast"
|
@@ -88,7 +89,7 @@ def get_weather_data():
|
|
88 |
except Exception as e:
|
89 |
return jsonify({"error": str(e)}), 500
|
90 |
|
91 |
-
def call_gemini_api(input_data):
|
92 |
"""
|
93 |
Enhanced prompt: We request a visually appealing Markdown report WITHOUT
|
94 |
showing raw CSS code blocks. Instead, we want a descriptive layout.
|
@@ -96,7 +97,7 @@ def call_gemini_api(input_data):
|
|
96 |
in a color-rich, well-spaced manner, but NOT to display raw CSS code.
|
97 |
"""
|
98 |
prompt = f"""
|
99 |
-
Create a visually appealing, farmer-friendly pest outbreak report in Markdown with the following:
|
100 |
1. A large, centered heading: "Pest Outbreak Dashboard Report".
|
101 |
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.
|
102 |
3. Several subheadings (e.g., "Agricultural Inputs", "Pest Outbreak Analysis", "Best Agricultural Practices", "Insights") with short paragraphs.
|
@@ -134,10 +135,12 @@ Important details from the user:
|
|
134 |
)
|
135 |
return response.text
|
136 |
|
|
|
137 |
@app.route('/predict', methods=['POST'])
|
138 |
def predict():
|
139 |
form_data = request.form.to_dict()
|
140 |
-
|
|
|
141 |
|
142 |
# Convert raw markdown to HTML
|
143 |
report_html = markdown.markdown(report_md)
|
|
|
36 |
lat, lon = validate_coordinates(lat, lon)
|
37 |
if lat is None or lon is None:
|
38 |
return jsonify({"error": "Invalid coordinates"}), 400
|
39 |
+
|
40 |
|
41 |
try:
|
42 |
forecast_url = "https://api.open-meteo.com/v1/forecast"
|
|
|
89 |
except Exception as e:
|
90 |
return jsonify({"error": str(e)}), 500
|
91 |
|
92 |
+
def call_gemini_api(input_data,language):
|
93 |
"""
|
94 |
Enhanced prompt: We request a visually appealing Markdown report WITHOUT
|
95 |
showing raw CSS code blocks. Instead, we want a descriptive layout.
|
|
|
97 |
in a color-rich, well-spaced manner, but NOT to display raw CSS code.
|
98 |
"""
|
99 |
prompt = f"""
|
100 |
+
Create a visually appealing, farmer-friendly pest outbreak report in Markdown with the following:Please generate the following soil report analysis entirely in {language}.
|
101 |
1. A large, centered heading: "Pest Outbreak Dashboard Report".
|
102 |
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.
|
103 |
3. Several subheadings (e.g., "Agricultural Inputs", "Pest Outbreak Analysis", "Best Agricultural Practices", "Insights") with short paragraphs.
|
|
|
135 |
)
|
136 |
return response.text
|
137 |
|
138 |
+
|
139 |
@app.route('/predict', methods=['POST'])
|
140 |
def predict():
|
141 |
form_data = request.form.to_dict()
|
142 |
+
language = data.get("language", "English")
|
143 |
+
report_md = call_gemini_api(form_data,language)
|
144 |
|
145 |
# Convert raw markdown to HTML
|
146 |
report_html = markdown.markdown(report_md)
|