Download answer_generator/formatter.py from Satyam0077/Project-Samarth-Intelligent-QA-System: direct link, hf CLI and curl.
- Browser
- Download file 1.04 kB
-
https://huggingface.co/spaces/Satyam0077/Project-Samarth-Intelligent-QA-System/resolve/main/answer_generator/formatter.py
- Command line
-
hf download hf://spaces/Satyam0077/Project-Samarth-Intelligent-QA-System/answer_generator/formatter.py
-
curl -L -o formatter.py https://huggingface.co/spaces/Satyam0077/Project-Samarth-Intelligent-QA-System/resolve/main/answer_generator/formatter.py
1.04 kB
| def format_response(result: dict, source: str): | |
| """Format the Q&A result for Streamlit display.""" | |
| if not result or "error" in result: | |
| return f"β {result.get('error', 'No valid data found.')}" | |
| states = [s.title() for s in result.get("states", [])] | |
| crop = result.get("crop", "N/A").title() | |
| text = f"π Analysis for {', '.join(states)} β Crop: {crop}\n\n" | |
| # π§οΈ Rainfall Summary | |
| rainfall = result.get("rainfall_summary", {}) | |
| if rainfall: | |
| text += "π§οΈ Average Rainfall (mm):\n" | |
| for state, value in rainfall.items(): | |
| text += f" β’ {state.title()}: {round(value, 2)}\n" | |
| text += "\n" | |
| # πΎ Production Summary | |
| production = result.get("production_summary", {}) | |
| if production: | |
| text += "πΎ Total Production (tonnes):\n" | |
| for state, value in production.items(): | |
| text += f" β’ {state.title()}: {int(value):,}\n" | |
| text += "\n" | |
| # π Citation | |
| text += f"π Data Source: {source}" | |
| return text | |