Spaces:
Sleeping
Sleeping
first fix2
Browse files- inference.py +15 -9
- preprocessing.py +6 -2
inference.py
CHANGED
|
@@ -16,15 +16,21 @@ def detect_text(text):
|
|
| 16 |
"possible_sources": None
|
| 17 |
}
|
| 18 |
|
| 19 |
-
def detect_image(url):
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
# batch detect
|
| 30 |
def detect_page(texts, images):
|
|
|
|
| 16 |
"possible_sources": None
|
| 17 |
}
|
| 18 |
|
| 19 |
+
def detect_image(url: str):
|
| 20 |
+
try:
|
| 21 |
+
image = load_image_from_url(url)
|
| 22 |
+
score = image_model.predict(image)
|
| 23 |
+
return {
|
| 24 |
+
"url": url,
|
| 25 |
+
"ai_probability": float(score),
|
| 26 |
+
"generation_type": "diffusion",
|
| 27 |
+
"possible_sources": None
|
| 28 |
+
}
|
| 29 |
+
except Exception as e:
|
| 30 |
+
return {
|
| 31 |
+
"url": url,
|
| 32 |
+
"error": str(e)
|
| 33 |
+
}
|
| 34 |
|
| 35 |
# batch detect
|
| 36 |
def detect_page(texts, images):
|
preprocessing.py
CHANGED
|
@@ -11,8 +11,12 @@ def clean_text(text: str):
|
|
| 11 |
|
| 12 |
|
| 13 |
def load_image_from_url(url: str):
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
image = Image.open(BytesIO(response.content)).convert("RGB")
|
| 18 |
return image
|
|
|
|
| 11 |
|
| 12 |
|
| 13 |
def load_image_from_url(url: str):
|
| 14 |
+
headers = {
|
| 15 |
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)"
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
response = requests.get(url, headers=headers, timeout=10)
|
| 19 |
+
response.raise_for_status() # будет ловить ошибки 4xx/5xx
|
| 20 |
|
| 21 |
image = Image.open(BytesIO(response.content)).convert("RGB")
|
| 22 |
return image
|