ginipick commited on
Commit
cfd0b77
Β·
verified Β·
1 Parent(s): 3ce7d3e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -15
app.py CHANGED
@@ -1165,9 +1165,7 @@ def generate_image(prompt: str):
1165
  if len(clean_prompt) < 3:
1166
  return None, None
1167
 
1168
- # Add timeout and better logging
1169
- st.write(f"Connecting to image API at {IMAGE_API_URL}...")
1170
-
1171
  try:
1172
  res = Client(IMAGE_API_URL).predict(
1173
  prompt = clean_prompt,
@@ -1178,25 +1176,41 @@ def generate_image(prompt: str):
1178
  seed = 3,
1179
  do_img2img = False,
1180
  api_name = "/generate_image",
1181
- timeout = 30 # Add timeout
1182
  )
1183
  except Exception as api_err:
1184
- st.error(f"Image API connection failed: {api_err}")
1185
- logging.error(f"Image API connection error: {api_err}")
1186
  return None, None
1187
 
1188
  if not res:
1189
- st.warning("Image API returned empty response")
1190
- logging.warning("Empty response from image API")
1191
  return None, None
1192
-
1193
- # Debug the response
1194
- st.write(f"API Response type: {type(res)}")
1195
- logging.info(f"Image API response: {res}")
1196
-
1197
  raw = res[0] if isinstance(res, list) else res
1198
- # Rest of your function...
1199
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1200
 
1201
  # ───────────────────────────── Kaggle API ─────────────────────────────
1202
  @st.cache_resource
 
1165
  if len(clean_prompt) < 3:
1166
  return None, None
1167
 
1168
+ # μ—¬κΈ°μ„œ API 호좜 μ‹œλ„
 
 
1169
  try:
1170
  res = Client(IMAGE_API_URL).predict(
1171
  prompt = clean_prompt,
 
1176
  seed = 3,
1177
  do_img2img = False,
1178
  api_name = "/generate_image",
1179
+ timeout = 30
1180
  )
1181
  except Exception as api_err:
1182
+ st.error(f"이미지 API μ—°κ²° μ‹€νŒ¨: {api_err}")
1183
+ logging.error(f"이미지 API μ—°κ²° 였λ₯˜: {api_err}")
1184
  return None, None
1185
 
1186
  if not res:
1187
+ logging.warning("이미지 APIκ°€ 빈 응닡을 λ°˜ν™˜ν•¨")
 
1188
  return None, None
1189
+
 
 
 
 
1190
  raw = res[0] if isinstance(res, list) else res
1191
+
1192
+ # 이미지 데이터 처리 (base64 인 경우)
1193
+ if isinstance(raw, str) and raw.startswith("data:image"):
1194
+ raw = raw.split(",", 1)[1]
1195
+ try:
1196
+ import base64
1197
+ img_bytes = base64.b64decode(raw)
1198
+ return img_bytes, clean_prompt
1199
+ except Exception as e:
1200
+ logging.error(f"base64 λ””μ½”λ”© μ‹€νŒ¨: {e}")
1201
+ return None, None
1202
+
1203
+ # URL인 경우
1204
+ elif isinstance(raw, str) and raw.startswith("http"):
1205
+ return raw, clean_prompt
1206
+
1207
+ # λ°”μ΄λ„ˆλ¦¬ 데이터인 경우
1208
+ else:
1209
+ return raw, clean_prompt
1210
+
1211
+ except Exception as e:
1212
+ logging.error(f"이미지 생성 였λ₯˜: {e}", exc_info=True)
1213
+ return None, None
1214
 
1215
  # ───────────────────────────── Kaggle API ─────────────────────────────
1216
  @st.cache_resource