AIcoder35235 commited on
Commit
e9a0cdd
·
verified ·
1 Parent(s): 9791dff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -5
app.py CHANGED
@@ -39,13 +39,17 @@ def predict(req: PredictRequest):
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
 
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