Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -429,37 +429,36 @@ Return JSON format:
|
|
| 429 |
print((out or "")[:1200])
|
| 430 |
|
| 431 |
try:
|
| 432 |
-
|
| 433 |
-
except Exception:
|
| 434 |
-
repair = f"""
|
| 435 |
-
You MUST output ONLY valid JSON. No explanations. No markdown. No extra text.
|
| 436 |
-
Start with "{{" and end with "}}".
|
| 437 |
-
Return the JSON again now.
|
| 438 |
|
|
|
|
|
|
|
|
|
|
| 439 |
PREVIOUS_OUTPUT:
|
| 440 |
{out}
|
| 441 |
""".strip()
|
| 442 |
|
| 443 |
-
|
| 444 |
|
| 445 |
-
|
| 446 |
-
|
| 447 |
|
|
|
|
| 448 |
return safe_json_extract(out2)
|
| 449 |
-
|
| 450 |
-
except Exception:
|
| 451 |
-
# Fallback: use OpenAI as verifier so pipeline never dies
|
| 452 |
-
fallback = openai_chat(
|
| 453 |
-
system="You are a STRICT fact-checker. Output ONLY valid JSON. Start with { and end with }. No markdown.",
|
| 454 |
-
user=prompt,
|
| 455 |
-
temperature=0.0
|
| 456 |
-
)
|
| 457 |
|
| 458 |
-
|
| 459 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 460 |
|
| 461 |
-
|
| 462 |
-
|
|
|
|
|
|
|
|
|
|
| 463 |
except Exception:
|
| 464 |
# Last resort: raise error including model outputs preview
|
| 465 |
raise gr.Error(
|
|
|
|
| 429 |
print((out or "")[:1200])
|
| 430 |
|
| 431 |
try:
|
| 432 |
+
return safe_json_extract(out)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 433 |
|
| 434 |
+
except Exception:
|
| 435 |
+
repair = f"""
|
| 436 |
+
You MUST output ONLY valid JSON...
|
| 437 |
PREVIOUS_OUTPUT:
|
| 438 |
{out}
|
| 439 |
""".strip()
|
| 440 |
|
| 441 |
+
out2 = gemini_generate(prompt + "\n\n" + repair, temperature=0.0)
|
| 442 |
|
| 443 |
+
print("=== GEMINI OUT2 (first 1200 chars) ===")
|
| 444 |
+
print((out2 or "")[:1200])
|
| 445 |
|
| 446 |
+
try:
|
| 447 |
return safe_json_extract(out2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 448 |
|
| 449 |
+
except Exception:
|
| 450 |
+
# Fallback
|
| 451 |
+
fallback = openai_chat(
|
| 452 |
+
"You are a STRICT fact-checker. Output ONLY valid JSON. Start with { and end with }. No markdown.",
|
| 453 |
+
prompt,
|
| 454 |
+
temperature=0.0
|
| 455 |
+
)
|
| 456 |
|
| 457 |
+
print("=== OPENAI FALLBACK OUT (first 1200 chars) ===")
|
| 458 |
+
print((fallback or "")[:1200])
|
| 459 |
+
|
| 460 |
+
return safe_json_extract(fallback)
|
| 461 |
+
|
| 462 |
except Exception:
|
| 463 |
# Last resort: raise error including model outputs preview
|
| 464 |
raise gr.Error(
|