Spaces:
Configuration error
Configuration error
Download app/generation/answer.py from Samaksh25/GST_RAG_BACKEND: direct link, hf CLI and curl.
- Browser
- Download file 695 Bytes
-
https://huggingface.co/spaces/Samaksh25/GST_RAG_BACKEND/resolve/main/app/generation/answer.py
- Command line
-
hf download hf://spaces/Samaksh25/GST_RAG_BACKEND/app/generation/answer.py
-
curl -L -o answer.py https://huggingface.co/spaces/Samaksh25/GST_RAG_BACKEND/resolve/main/app/generation/answer.py
695 Bytes
| def generate_answer(question: str, context: str) -> str: | |
| """ | |
| Deterministic, demo-safe answer generator. | |
| Uses retrieved context only. | |
| """ | |
| if not context or context.strip() == "": | |
| return "The answer is not available in the provided documents." | |
| # Simple conclusion-first formatting | |
| lines = context.strip().split("\n") | |
| summary = [] | |
| for line in lines: | |
| if len(line.strip()) > 30: | |
| summary.append(line.strip()) | |
| if len(summary) == 3: | |
| break | |
| if not summary: | |
| return "The answer is not available in the provided documents." | |
| return ( | |
| "Based on the documents:\n" | |
| + " ".join(summary) | |
| ) | |