Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -39,13 +39,17 @@ def predict(req: PredictRequest):
|
|
| 39 |
img = None
|
| 40 |
|
| 41 |
if req.image_url:
|
| 42 |
-
#
|
| 43 |
-
headers = {
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
if response.status_code != 200:
|
| 47 |
-
|
| 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
|
|
|
|
| 39 |
img = None
|
| 40 |
|
| 41 |
if req.image_url:
|
| 42 |
+
# The "Super-Human" header pack
|
| 43 |
+
headers = {
|
| 44 |
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36",
|
| 45 |
+
"Accept": "image/avif,image/webp,image/apng,image/*,*/*;q=0.8",
|
| 46 |
+
"Referer": "https://google.com" # This tricks the site into thinking you came from a search
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
response = requests.get(req.image_url, stream=True, headers=headers, timeout=10)
|
| 50 |
|
| 51 |
if response.status_code != 200:
|
| 52 |
+
raise Exception(f"The image site blocked us with error: {response.status_code}. Try a different URL or Base64 upload.")
|
|
|
|
| 53 |
|
| 54 |
img = Image.open(response.raw).convert("RGB")
|
| 55 |
# 2. Handle Base64 Input
|