LiamKhoaLe commited on
Commit
40f5138
·
1 Parent(s): 4a0564f

Solve error UI display JSON

Browse files
Files changed (2) hide show
  1. .DS_Store +0 -0
  2. app.py +9 -3
.DS_Store CHANGED
Binary files a/.DS_Store and b/.DS_Store differ
 
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  # Interview Q&A – FastAPI backend
2
  import base64, io, json, logging, os, tempfile
3
  from pathlib import Path
@@ -162,9 +163,14 @@ async def image_question(file: UploadFile = File(...)):
162
  text = call_gemini(prompt, vision_part)
163
  try:
164
  parsed = json.loads(text)
165
- question, answer = parsed["question"], parsed["answer"]
166
- except (json.JSONDecodeError, KeyError):
167
- # Fallback: treat whole reply as answer
 
 
 
 
 
168
  question, answer = "[Extracted from screenshot]", text
169
  return JSONResponse({"question": question, "answer": answer, "memory_mb": memory_mb()})
170
 
 
1
+ # https://binkhoale1812-interview-ai.hf.space/
2
  # Interview Q&A – FastAPI backend
3
  import base64, io, json, logging, os, tempfile
4
  from pathlib import Path
 
163
  text = call_gemini(prompt, vision_part)
164
  try:
165
  parsed = json.loads(text)
166
+ # Make sure these are clean plain strings for rendering
167
+ question = str(parsed.get("question", "")).strip()
168
+ answer = str(parsed.get("answer", "")).strip()
169
+ # Remove accidental outer quotes if double-wrapped
170
+ if question.startswith("{") or answer.startswith("{"):
171
+ raise ValueError("Wrapped JSON detected inside field")
172
+ except Exception as e:
173
+ logger.warning(f"[PARSE] Failed to cleanly extract JSON fields: {e}")
174
  question, answer = "[Extracted from screenshot]", text
175
  return JSONResponse({"question": question, "answer": answer, "memory_mb": memory_mb()})
176