Spaces:
Runtime error
Runtime error
update
Browse files
app.py
CHANGED
|
@@ -40,6 +40,22 @@ def process_image(image_prompt):
|
|
| 40 |
return encoded_img, image_hash
|
| 41 |
|
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
def is_chinese(text):
|
| 44 |
zh_pattern = re.compile(u'[\u4e00-\u9fa5]+')
|
| 45 |
return zh_pattern.search(text)
|
|
@@ -78,7 +94,7 @@ def post(
|
|
| 78 |
"User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36",
|
| 79 |
}
|
| 80 |
if image_prompt:
|
| 81 |
-
encoded_img, image_hash =
|
| 82 |
print(f"image_hash:{image_hash}, hidden_image_hash:{hidden_image}")
|
| 83 |
|
| 84 |
if hidden_image is not None and image_hash != hidden_image:
|
|
|
|
| 40 |
return encoded_img, image_hash
|
| 41 |
|
| 42 |
|
| 43 |
+
def process_image_without_resize(image_prompt):
|
| 44 |
+
image = Image.open(image_prompt)
|
| 45 |
+
print(f"height:{image.height}, width:{image.width}")
|
| 46 |
+
timestamp = int(time.time())
|
| 47 |
+
file_ext = os.path.splitext(image_prompt)[1]
|
| 48 |
+
filename = f"examples/{timestamp}{file_ext}"
|
| 49 |
+
image.save(filename)
|
| 50 |
+
print(f"temporal filename {filename}")
|
| 51 |
+
with open(filename, "rb") as image_file:
|
| 52 |
+
bytes = base64.b64encode(image_file.read())
|
| 53 |
+
encoded_img = str(bytes, encoding='utf-8')
|
| 54 |
+
image_hash = hashlib.sha256(bytes).hexdigest()
|
| 55 |
+
os.remove(filename)
|
| 56 |
+
return encoded_img, image_hash
|
| 57 |
+
|
| 58 |
+
|
| 59 |
def is_chinese(text):
|
| 60 |
zh_pattern = re.compile(u'[\u4e00-\u9fa5]+')
|
| 61 |
return zh_pattern.search(text)
|
|
|
|
| 94 |
"User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36",
|
| 95 |
}
|
| 96 |
if image_prompt:
|
| 97 |
+
encoded_img, image_hash = process_image_without_resize(image_prompt)
|
| 98 |
print(f"image_hash:{image_hash}, hidden_image_hash:{hidden_image}")
|
| 99 |
|
| 100 |
if hidden_image is not None and image_hash != hidden_image:
|