Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -38,14 +38,16 @@ def predict(req: PredictRequest):
|
|
| 38 |
try:
|
| 39 |
img = None
|
| 40 |
|
| 41 |
-
# 1. Handle URL Input (with the Wikipedia bypass fix from Task 24!)
|
| 42 |
if req.image_url:
|
|
|
|
| 43 |
headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)"}
|
| 44 |
response = requests.get(req.image_url, stream=True, headers=headers)
|
|
|
|
| 45 |
if response.status_code != 200:
|
| 46 |
-
|
|
|
|
|
|
|
| 47 |
img = Image.open(response.raw).convert("RGB")
|
| 48 |
-
|
| 49 |
# 2. Handle Base64 Input
|
| 50 |
elif req.image:
|
| 51 |
b64_data = req.image
|
|
|
|
| 38 |
try:
|
| 39 |
img = None
|
| 40 |
|
|
|
|
| 41 |
if req.image_url:
|
| 42 |
+
# This "User-Agent" is the ID card that lets us download images
|
| 43 |
headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)"}
|
| 44 |
response = requests.get(req.image_url, stream=True, headers=headers)
|
| 45 |
+
|
| 46 |
if response.status_code != 200:
|
| 47 |
+
# This will tell us EXACTLY why it failed (403, 404, etc.)
|
| 48 |
+
raise Exception(f"External site returned error: {response.status_code}")
|
| 49 |
+
|
| 50 |
img = Image.open(response.raw).convert("RGB")
|
|
|
|
| 51 |
# 2. Handle Base64 Input
|
| 52 |
elif req.image:
|
| 53 |
b64_data = req.image
|