Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -22,13 +22,16 @@ task_history = []
|
|
22 |
BOX_TAG_PATTERN = r"<box>([\s\S]*?)</box>"
|
23 |
PUNCTUATION = "!?。"#$%&'()*+,-/:;<=>@[\]^_`{|}~⦅⦆「」、、〃》「」『』​``【oaicite:0】``​〔〕〖〗〘〙〚〛〜〝〞〟〰〾〿–—‘’‛“”„‟…‧﹏."
|
24 |
|
|
|
|
|
|
|
|
|
25 |
def save_image(image_file) -> str:
|
26 |
upload_dir = "uploaded_images"
|
27 |
print("Creating upload directory if it doesn't exist.")
|
28 |
os.makedirs(upload_dir, exist_ok=True)
|
29 |
-
|
30 |
try:
|
31 |
-
print("Attempting to open
|
32 |
image = Image.open(image_file).convert("RGB")
|
33 |
file_name = secrets.token_hex(10) + ".png"
|
34 |
file_path = os.path.join(upload_dir, file_name)
|
@@ -44,6 +47,7 @@ def save_image(image_file) -> str:
|
|
44 |
print(f"An unexpected error occurred: {e}")
|
45 |
return None
|
46 |
|
|
|
47 |
def clean_response(response: str) -> str:
|
48 |
response = re.sub(r'<ref>(.*?)</ref>(?:<box>.*?</box>)*(?:<quad>.*?</quad>)*', r'\1', response).strip()
|
49 |
return response
|
|
|
22 |
BOX_TAG_PATTERN = r"<box>([\s\S]*?)</box>"
|
23 |
PUNCTUATION = "!?。"#$%&'()*+,-/:;<=>@[\]^_`{|}~⦅⦆「」、、〃》「」『』​``【oaicite:0】``​〔〕〖〗〘〙〚〛〜〝〞〟〰〾〿–—‘’‛“”„‟…‧﹏."
|
24 |
|
25 |
+
import os
|
26 |
+
from PIL import Image, UnidentifiedImageError
|
27 |
+
import secrets
|
28 |
+
|
29 |
def save_image(image_file) -> str:
|
30 |
upload_dir = "uploaded_images"
|
31 |
print("Creating upload directory if it doesn't exist.")
|
32 |
os.makedirs(upload_dir, exist_ok=True)
|
|
|
33 |
try:
|
34 |
+
print(f"Attempting to open the image file: {image_file.name}")
|
35 |
image = Image.open(image_file).convert("RGB")
|
36 |
file_name = secrets.token_hex(10) + ".png"
|
37 |
file_path = os.path.join(upload_dir, file_name)
|
|
|
47 |
print(f"An unexpected error occurred: {e}")
|
48 |
return None
|
49 |
|
50 |
+
|
51 |
def clean_response(response: str) -> str:
|
52 |
response = re.sub(r'<ref>(.*?)</ref>(?:<box>.*?</box>)*(?:<quad>.*?</quad>)*', r'\1', response).strip()
|
53 |
return response
|