salso commited on
Commit
d548d36
Β·
verified Β·
1 Parent(s): f43190d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -9
app.py CHANGED
@@ -69,18 +69,21 @@ def process_image_and_text(subject_image, adapter_dict, prompt, _unused1, _unuse
69
  if BASETEN_API_KEY:
70
  headers["Authorization"] = f"Api-Key {BASETEN_API_KEY}"
71
 
72
- resp = requests.post(BASETEN_MODEL_URL, headers=headers, json=payload, timeout=120)
73
  resp.raise_for_status()
74
-
75
- if resp.headers.get("content-type", "").startswith("image/"):
76
- raw_img = Image.open(BytesIO(resp.content))
 
 
 
 
 
 
 
77
  else:
78
- url = resp.json().get("image_url")
79
- if not url:
80
- raise gr.Error("Baseten response missing image data.")
81
- raw_img = Image.open(BytesIO(requests.get(url, timeout=120).content))
82
 
83
- return [[raw_img]], raw_img
84
 
85
  # ────────── Header HTML ──────────
86
  header_html = """
 
69
  if BASETEN_API_KEY:
70
  headers["Authorization"] = f"Api-Key {BASETEN_API_KEY}"
71
 
72
+ resp = requests.post(BASETEN_MODEL_URL, headers=headers, json=payload, timeout=180)
73
  resp.raise_for_status()
74
+ data = resp.json()
75
+ print (data)
76
+
77
+ # If Baseten returns [cond1.condition, raw_img] format
78
+ if isinstance(data, list) and len(data) == 2:
79
+ # If the second item is base64-encoded image string
80
+ try:
81
+ raw_img = Image.open(BytesIO(base64.b64decode(data[1])))
82
+ except Exception:
83
+ raise gr.Error("Failed to decode image from Baseten response.")
84
  else:
85
+ raise gr.Error("Unexpected response format from Baseten.")
 
 
 
86
 
 
87
 
88
  # ────────── Header HTML ──────────
89
  header_html = """