Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -403,7 +403,7 @@ def merge_health(ay, we):
|
|
| 403 |
merged.sort(key=lambda m: m.get("score", 0), reverse=True)
|
| 404 |
return merged[:12]
|
| 405 |
|
| 406 |
-
def handle_health(user_text: str, lang: str) -> str:
|
| 407 |
choice = decide_health_namespace(user_text)
|
| 408 |
if choice == "ayurvedic":
|
| 409 |
matches = query_pinecone("ayurvedic", user_text, 14)
|
|
@@ -418,6 +418,9 @@ def handle_health(user_text: str, lang: str) -> str:
|
|
| 418 |
reply_type = "detailed" if any(k in user_text.lower() for k in ["detail", "explain", "why", "how"]) else "brief"
|
| 419 |
|
| 420 |
context = build_context(matches) if matches else ""
|
|
|
|
|
|
|
|
|
|
| 421 |
payload = {
|
| 422 |
"context": context,
|
| 423 |
"question": user_text,
|
|
@@ -425,11 +428,10 @@ def handle_health(user_text: str, lang: str) -> str:
|
|
| 425 |
"reply_type": reply_type,
|
| 426 |
}
|
| 427 |
ans = (post_hf(URL_SUMMARIZER, payload) or "").strip()
|
|
|
|
|
|
|
|
|
|
| 428 |
|
| 429 |
-
# Add gentle medical disclaimer once
|
| 430 |
-
disclaimer = ("\n\n**Note:** This information is educational and not a substitute for professional medical advice. "
|
| 431 |
-
"Consult a qualified clinician for diagnosis or treatment, especially for urgent or serious symptoms.")
|
| 432 |
-
return (ans or "I couldn't find enough health context to answer well. Could you add a few details (age, symptoms, duration)?") + disclaimer
|
| 433 |
|
| 434 |
def handle_realtime(user_text: str, lang: str) -> str:
|
| 435 |
# Real search + summarization
|
|
@@ -508,6 +510,7 @@ async def reset_session(request: Request):
|
|
| 508 |
async def generate_result(request: Request, user_agent: str = Header(default="")):
|
| 509 |
body = await request.json()
|
| 510 |
raw_text = (body.get("message") or "").strip()
|
|
|
|
| 511 |
if not raw_text:
|
| 512 |
return JSONResponse(status_code=400, content={"response": "No message provided"})
|
| 513 |
|
|
@@ -546,7 +549,7 @@ async def generate_result(request: Request, user_agent: str = Header(default="")
|
|
| 546 |
|
| 547 |
handlers = {
|
| 548 |
"spiritual_guidance": lambda t, l: handle_spiritual(t, l),
|
| 549 |
-
"health_wellness": lambda t, l: handle_health(t, l),
|
| 550 |
"realtime_query": lambda t, l: handle_realtime(t, l),
|
| 551 |
"generate_image": lambda t, l: handle_image(t, l),
|
| 552 |
"other_query": lambda t, l: handle_other(t, l, context_extra=convo_ctx),
|
|
|
|
| 403 |
merged.sort(key=lambda m: m.get("score", 0), reverse=True)
|
| 404 |
return merged[:12]
|
| 405 |
|
| 406 |
+
def handle_health(user_text: str, lang: str, image_text: str = "") -> str:
|
| 407 |
choice = decide_health_namespace(user_text)
|
| 408 |
if choice == "ayurvedic":
|
| 409 |
matches = query_pinecone("ayurvedic", user_text, 14)
|
|
|
|
| 418 |
reply_type = "detailed" if any(k in user_text.lower() for k in ["detail", "explain", "why", "how"]) else "brief"
|
| 419 |
|
| 420 |
context = build_context(matches) if matches else ""
|
| 421 |
+
if image_text:
|
| 422 |
+
context = (context + "\n\nExtracted from health image:\n" + image_text).strip()
|
| 423 |
+
|
| 424 |
payload = {
|
| 425 |
"context": context,
|
| 426 |
"question": user_text,
|
|
|
|
| 428 |
"reply_type": reply_type,
|
| 429 |
}
|
| 430 |
ans = (post_hf(URL_SUMMARIZER, payload) or "").strip()
|
| 431 |
+
disclaimer = ("\n\n**Note:** This is educational, not a medical diagnosis. "
|
| 432 |
+
"Consult a clinician for personalized care.")
|
| 433 |
+
return ans + disclaimer if ans else "I couldn't parse enough context—could you add a few details?"
|
| 434 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 435 |
|
| 436 |
def handle_realtime(user_text: str, lang: str) -> str:
|
| 437 |
# Real search + summarization
|
|
|
|
| 510 |
async def generate_result(request: Request, user_agent: str = Header(default="")):
|
| 511 |
body = await request.json()
|
| 512 |
raw_text = (body.get("message") or "").strip()
|
| 513 |
+
image_text = (body.get("image_text") or "").strip()
|
| 514 |
if not raw_text:
|
| 515 |
return JSONResponse(status_code=400, content={"response": "No message provided"})
|
| 516 |
|
|
|
|
| 549 |
|
| 550 |
handlers = {
|
| 551 |
"spiritual_guidance": lambda t, l: handle_spiritual(t, l),
|
| 552 |
+
"health_wellness": lambda t, l: handle_health(t, l, image_text=image_text),
|
| 553 |
"realtime_query": lambda t, l: handle_realtime(t, l),
|
| 554 |
"generate_image": lambda t, l: handle_image(t, l),
|
| 555 |
"other_query": lambda t, l: handle_other(t, l, context_extra=convo_ctx),
|