Update server.py
Browse files
server.py
CHANGED
|
@@ -11,7 +11,7 @@ from fastapi.middleware.cors import CORSMiddleware
|
|
| 11 |
from pydantic import BaseModel
|
| 12 |
from dotenv import dotenv_values
|
| 13 |
|
| 14 |
-
# Import
|
| 15 |
from tools import (
|
| 16 |
open_meteo,
|
| 17 |
tomorrow_io,
|
|
@@ -319,7 +319,6 @@ async def generate_ai_alert(latitude: float, longitude: float, crop: str,
|
|
| 319 |
'precipitation_forecast': daily_forecast.get('precipitation_sum', [0, 0, 0])[:3]
|
| 320 |
}
|
| 321 |
|
| 322 |
-
# Use the generate_weather_alert function from your tools
|
| 323 |
ai_alert = await alert_generation_tools.generate_weather_alert(
|
| 324 |
crop=crop,
|
| 325 |
weather_data=weather_context,
|
|
@@ -329,7 +328,7 @@ async def generate_ai_alert(latitude: float, longitude: float, crop: str,
|
|
| 329 |
longitude=longitude
|
| 330 |
)
|
| 331 |
|
| 332 |
-
# Extract AI response
|
| 333 |
if isinstance(ai_alert, dict):
|
| 334 |
alert_description = ai_alert.get('alert', 'Weather update for agricultural activities')
|
| 335 |
impact_description = ai_alert.get('impact', 'Monitor crops regularly')
|
|
@@ -709,7 +708,7 @@ async def a2a_telegram_endpoint(request: AlertRequest):
|
|
| 709 |
"""Telegram agent endpoint"""
|
| 710 |
return telegram_agent.create_telegram_message(request.alert_json)
|
| 711 |
|
| 712 |
-
# MCP RPC handler
|
| 713 |
@app.post("/mcp-rpc")
|
| 714 |
async def mcp_rpc_handler(request: dict):
|
| 715 |
"""JSON-RPC handler for MCP integration"""
|
|
@@ -801,16 +800,12 @@ async def general_exception_handler(request, exc):
|
|
| 801 |
}
|
| 802 |
|
| 803 |
|
| 804 |
-
|
| 805 |
-
|
| 806 |
# UI
|
| 807 |
-
|
| 808 |
-
|
| 809 |
import gradio as gr
|
| 810 |
import threading
|
| 811 |
import time
|
| 812 |
|
| 813 |
-
# Bihar districts list
|
| 814 |
BIHAR_DISTRICTS = [
|
| 815 |
"Patna", "Gaya", "Bhagalpur", "Muzaffarpur", "Darbhanga", "Siwan",
|
| 816 |
"Begusarai", "Katihar", "Nalanda", "Rohtas", "Saran", "Samastipur",
|
|
@@ -923,7 +918,6 @@ def format_agent_responses(agent_responses):
|
|
| 923 |
formatted = ["## π± Agent Responses", ""]
|
| 924 |
|
| 925 |
for agent_name, response in agent_responses.items():
|
| 926 |
-
# Ensure agent_name is string
|
| 927 |
agent_name_str = str(agent_name)
|
| 928 |
clean_name = agent_name_str.replace("π± ", "").replace("π ", "").replace("ποΈ ", "").replace("π€ ", "")
|
| 929 |
|
|
|
|
| 11 |
from pydantic import BaseModel
|
| 12 |
from dotenv import dotenv_values
|
| 13 |
|
| 14 |
+
# Import tools
|
| 15 |
from tools import (
|
| 16 |
open_meteo,
|
| 17 |
tomorrow_io,
|
|
|
|
| 319 |
'precipitation_forecast': daily_forecast.get('precipitation_sum', [0, 0, 0])[:3]
|
| 320 |
}
|
| 321 |
|
|
|
|
| 322 |
ai_alert = await alert_generation_tools.generate_weather_alert(
|
| 323 |
crop=crop,
|
| 324 |
weather_data=weather_context,
|
|
|
|
| 328 |
longitude=longitude
|
| 329 |
)
|
| 330 |
|
| 331 |
+
# Extract AI response
|
| 332 |
if isinstance(ai_alert, dict):
|
| 333 |
alert_description = ai_alert.get('alert', 'Weather update for agricultural activities')
|
| 334 |
impact_description = ai_alert.get('impact', 'Monitor crops regularly')
|
|
|
|
| 708 |
"""Telegram agent endpoint"""
|
| 709 |
return telegram_agent.create_telegram_message(request.alert_json)
|
| 710 |
|
| 711 |
+
# MCP RPC handler
|
| 712 |
@app.post("/mcp-rpc")
|
| 713 |
async def mcp_rpc_handler(request: dict):
|
| 714 |
"""JSON-RPC handler for MCP integration"""
|
|
|
|
| 800 |
}
|
| 801 |
|
| 802 |
|
|
|
|
|
|
|
| 803 |
# UI
|
|
|
|
|
|
|
| 804 |
import gradio as gr
|
| 805 |
import threading
|
| 806 |
import time
|
| 807 |
|
| 808 |
+
# Bihar districts list for dropdown
|
| 809 |
BIHAR_DISTRICTS = [
|
| 810 |
"Patna", "Gaya", "Bhagalpur", "Muzaffarpur", "Darbhanga", "Siwan",
|
| 811 |
"Begusarai", "Katihar", "Nalanda", "Rohtas", "Saran", "Samastipur",
|
|
|
|
| 918 |
formatted = ["## π± Agent Responses", ""]
|
| 919 |
|
| 920 |
for agent_name, response in agent_responses.items():
|
|
|
|
| 921 |
agent_name_str = str(agent_name)
|
| 922 |
clean_name = agent_name_str.replace("π± ", "").replace("π ", "").replace("ποΈ ", "").replace("π€ ", "")
|
| 923 |
|