Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,7 +9,8 @@ import torch
|
|
| 9 |
import os
|
| 10 |
from PIL import Image, ImageDraw, UnidentifiedImageError
|
| 11 |
|
| 12 |
-
|
|
|
|
| 13 |
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
| 14 |
model = AutoModelForCausalLM.from_pretrained(model_name, trust_remote_code=True).eval()
|
| 15 |
model.generation_config = GenerationConfig.from_pretrained(model_name, trust_remote_code=True)
|
|
@@ -36,18 +37,20 @@ def clean_response(response: str) -> str:
|
|
| 36 |
|
| 37 |
def chat_with_model(image_path=None, text_query=None, history=None):
|
| 38 |
default_image_path = 'https://huggingface.co/spaces/Tonic1/Official-Qwen-VL-Chat/blob/main/2saj7l.png'
|
| 39 |
-
|
| 40 |
if image_path:
|
| 41 |
-
|
|
|
|
| 42 |
try:
|
| 43 |
-
with Image.open(
|
| 44 |
-
print(f"Image {
|
| 45 |
-
except UnidentifiedImageError
|
| 46 |
-
print(f"Error
|
| 47 |
-
|
| 48 |
else:
|
| 49 |
-
print(f"
|
| 50 |
-
|
|
|
|
|
|
|
| 51 |
else:
|
| 52 |
print("No image path provided, using default image.")
|
| 53 |
image_path = default_image_path
|
|
|
|
| 9 |
import os
|
| 10 |
from PIL import Image, ImageDraw, UnidentifiedImageError
|
| 11 |
|
| 12 |
+
base_url = "https://huggingface.co/spaces/Tonic1/Official-Qwen-VL-Chat"
|
| 13 |
+
model_name = "Qwen/Qwen-VL-Chat"
|
| 14 |
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
| 15 |
model = AutoModelForCausalLM.from_pretrained(model_name, trust_remote_code=True).eval()
|
| 16 |
model.generation_config = GenerationConfig.from_pretrained(model_name, trust_remote_code=True)
|
|
|
|
| 37 |
|
| 38 |
def chat_with_model(image_path=None, text_query=None, history=None):
|
| 39 |
default_image_path = 'https://huggingface.co/spaces/Tonic1/Official-Qwen-VL-Chat/blob/main/2saj7l.png'
|
|
|
|
| 40 |
if image_path:
|
| 41 |
+
full_image_path = os.path.join(base_url, image_path) if base_url else image_path
|
| 42 |
+
if os.path.isfile(full_image_path):
|
| 43 |
try:
|
| 44 |
+
with Image.open(full_image_path) as img:
|
| 45 |
+
print(f"Image {full_image_path} opened successfully.")
|
| 46 |
+
except UnidentifiedImageError:
|
| 47 |
+
print(f"Error: The file at {full_image_path} is not a recognizable image.")
|
| 48 |
+
full_image_path = default_image_path
|
| 49 |
else:
|
| 50 |
+
print(f"File not found: {full_image_path}")
|
| 51 |
+
full_image_path = default_image_path
|
| 52 |
+
else:
|
| 53 |
+
full_image_path = default_image_path
|
| 54 |
else:
|
| 55 |
print("No image path provided, using default image.")
|
| 56 |
image_path = default_image_path
|