Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -34,13 +34,6 @@ def save_image(image_file) -> str:
|
|
34 |
print(f"Creating upload directory at {upload_dir} if it doesn't exist.")
|
35 |
os.makedirs(upload_dir, exist_ok=True)
|
36 |
try:
|
37 |
-
temp_file_path = image_file.name
|
38 |
-
print(f"Attempting to open the image file: {temp_file_path}")
|
39 |
-
if os.path.exists(temp_file_path) and os.path.getsize(temp_file_path) > 0:
|
40 |
-
print(f"File exists and size is {os.path.getsize(temp_file_path)} bytes")
|
41 |
-
else:
|
42 |
-
print("File does not exist or is empty.")
|
43 |
-
return None
|
44 |
image = Image.open(image_file).convert("RGB")
|
45 |
file_name = secrets.token_hex(10) + ".png"
|
46 |
file_path = os.path.join(upload_dir, file_name)
|
@@ -62,16 +55,15 @@ def clean_response(response: str) -> str:
|
|
62 |
|
63 |
def chat_with_model(image_path=None, text_query=None, history=None):
|
64 |
if image_path:
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
return "Error: Uploaded file not found."
|
75 |
else:
|
76 |
print("No image path provided, using text-only mode.")
|
77 |
|
@@ -124,7 +116,6 @@ def process_input(text=None, file=None, task_history=None):
|
|
124 |
clean_response = re.sub(r'<ref>(.*?)</ref>(?:<box>.*?</box>)*(?:<quad>.*?</quad>)*', r'\1', response).strip()
|
125 |
return [("bot", clean_response)], task_history
|
126 |
|
127 |
-
# Define Gradio interface
|
128 |
with gr.Blocks() as demo:
|
129 |
gr.Markdown("""
|
130 |
# 🙋🏻♂️欢迎来到🌟Tonic 的🦆Qwen-VL-Chat🤩Bot!🚀
|
@@ -141,7 +132,7 @@ Join us: TeamTonic is always making cool demos! Join our active builder's comm
|
|
141 |
with gr.Column(scale=1):
|
142 |
with gr.Row():
|
143 |
query = gr.Textbox(lines=2, label='Input', placeholder="Type your message here...")
|
144 |
-
file_upload = gr.
|
145 |
submit_btn = gr.Button("Submit")
|
146 |
|
147 |
task_history = gr.State([])
|
|
|
34 |
print(f"Creating upload directory at {upload_dir} if it doesn't exist.")
|
35 |
os.makedirs(upload_dir, exist_ok=True)
|
36 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
image = Image.open(image_file).convert("RGB")
|
38 |
file_name = secrets.token_hex(10) + ".png"
|
39 |
file_path = os.path.join(upload_dir, file_name)
|
|
|
55 |
|
56 |
def chat_with_model(image_path=None, text_query=None, history=None):
|
57 |
if image_path:
|
58 |
+
try:
|
59 |
+
with Image.open(image_path) as img:
|
60 |
+
print(f"Image {image_path} opened successfully.")
|
61 |
+
except UnidentifiedImageError:
|
62 |
+
print(f"Error: The file at {image_path} is not a recognizable image.")
|
63 |
+
return "Error: Uploaded file is not a recognizable image."
|
64 |
+
except Exception as e:
|
65 |
+
print(f"An error occurred while processing the image: {e}")
|
66 |
+
return "An error occurred while processing your request."
|
|
|
67 |
else:
|
68 |
print("No image path provided, using text-only mode.")
|
69 |
|
|
|
116 |
clean_response = re.sub(r'<ref>(.*?)</ref>(?:<box>.*?</box>)*(?:<quad>.*?</quad>)*', r'\1', response).strip()
|
117 |
return [("bot", clean_response)], task_history
|
118 |
|
|
|
119 |
with gr.Blocks() as demo:
|
120 |
gr.Markdown("""
|
121 |
# 🙋🏻♂️欢迎来到🌟Tonic 的🦆Qwen-VL-Chat🤩Bot!🚀
|
|
|
132 |
with gr.Column(scale=1):
|
133 |
with gr.Row():
|
134 |
query = gr.Textbox(lines=2, label='Input', placeholder="Type your message here...")
|
135 |
+
file_upload = gr.Image(type="filepath", label="Upload Image")
|
136 |
submit_btn = gr.Button("Submit")
|
137 |
|
138 |
task_history = gr.State([])
|