webolavo commited on
Commit
55bb2cf
Β·
verified Β·
1 Parent(s): b34943b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -2
app.py CHANGED
@@ -223,14 +223,37 @@ def health():
223
  # ─── Endpoint 1: Ω…Ω† Ψ₯آافة Chrome ─────────────────────────────────
224
  @app.post("/analyze")
225
  async def analyze_from_url(request: ImageUrlRequest):
 
226
  try:
227
  async with httpx.AsyncClient(timeout=30) as client:
228
- response = await client.get(request.image_url)
229
- response.raise_for_status()
230
  image_bytes = response.content
231
  except Exception as e:
232
  raise HTTPException(status_code=400, detail=f"فشل ΨͺΨ­Ω…ΩŠΩ„ Ψ§Ω„Ψ΅ΩˆΨ±Ψ©: {str(e)}")
233
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
234
  try:
235
  image = Image.open(io.BytesIO(image_bytes)).convert("RGB")
236
  except Exception as e:
 
223
  # ─── Endpoint 1: Ω…Ω† Ψ₯آافة Chrome ─────────────────────────────────
224
  @app.post("/analyze")
225
  async def analyze_from_url(request: ImageUrlRequest):
226
+ image_url = request.image_url
227
  try:
228
  async with httpx.AsyncClient(timeout=30) as client:
229
+ response = await client.get(image_url)
 
230
  image_bytes = response.content
231
  except Exception as e:
232
  raise HTTPException(status_code=400, detail=f"فشل ΨͺΨ­Ω…ΩŠΩ„ Ψ§Ω„Ψ΅ΩˆΨ±Ψ©: {str(e)}")
233
 
234
+ content_type = response.headers.get("Content-Type", "")
235
+ print("========== IMAGE DEBUG ==========")
236
+ print("Requested URL:", image_url)
237
+ print("Status Code:", response.status_code)
238
+ print("Content-Type:", content_type)
239
+ print("Content-Length:", response.headers.get("Content-Length"))
240
+ print("First 300 bytes:")
241
+ print(response.content[:300])
242
+ print("=================================")
243
+
244
+ if not content_type.lower().startswith("image/"):
245
+ return {
246
+ "url": image_url,
247
+ "status_code": response.status_code,
248
+ "content_type": content_type,
249
+ "preview": response.content[:300].decode("utf-8", errors="replace"),
250
+ }
251
+
252
+ try:
253
+ response.raise_for_status()
254
+ except httpx.HTTPStatusError as e:
255
+ raise HTTPException(status_code=400, detail=f"Image download failed: {str(e)}")
256
+
257
  try:
258
  image = Image.open(io.BytesIO(image_bytes)).convert("RGB")
259
  except Exception as e: