LiamKhoaLe commited on
Commit
0dc9435
·
1 Parent(s): 40f5138

Solve error UI display JSON

Browse files
Files changed (1) hide show
  1. app.py +4 -2
app.py CHANGED
@@ -1,6 +1,7 @@
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
5
  from typing import Dict
6
 
@@ -161,8 +162,9 @@ async def image_question(file: UploadFile = File(...)):
161
  )
162
  # Send prompt and image
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()
 
1
  # https://binkhoale1812-interview-ai.hf.space/
2
  # Interview Q&A – FastAPI backend
3
  import base64, io, json, logging, os, tempfile
4
+ import re
5
  from pathlib import Path
6
  from typing import Dict
7
 
 
162
  )
163
  # Send prompt and image
164
  text = call_gemini(prompt, vision_part)
165
+ try: # Parsed from JSON (rm bracket and markdown)
166
+ cleaned = re.sub(r"^```json\s*|\s*```$", "", text.strip(), flags=re.IGNORECASE | re.MULTILINE)
167
+ parsed = json.loads(cleaned)
168
  # Make sure these are clean plain strings for rendering
169
  question = str(parsed.get("question", "")).strip()
170
  answer = str(parsed.get("answer", "")).strip()