Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -28,13 +28,17 @@ device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
28 |
model = model.to(device)
|
29 |
|
30 |
def load_image(image_file):
|
31 |
-
"""
|
32 |
-
if isinstance(image_file,
|
|
|
|
|
|
|
33 |
response = requests.get(image_file)
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
|
|
38 |
|
39 |
def llava_infer(image, text, temperature, top_p, max_tokens):
|
40 |
"""LLaVA 模型推理"""
|
|
|
28 |
model = model.to(device)
|
29 |
|
30 |
def load_image(image_file):
|
31 |
+
"""确保 image 是 `PIL.Image`"""
|
32 |
+
if isinstance(image_file, Image.Image):
|
33 |
+
return image_file.convert("RGB") # 直接返回 `PIL.Image`
|
34 |
+
|
35 |
+
elif isinstance(image_file, str) and (image_file.startswith('http') or image_file.startswith('https')):
|
36 |
response = requests.get(image_file)
|
37 |
+
return Image.open(BytesIO(response.content)).convert('RGB')
|
38 |
+
|
39 |
+
else: # 这里如果 `image_file` 是路径
|
40 |
+
return Image.open(image_file).convert("RGB")
|
41 |
+
|
42 |
|
43 |
def llava_infer(image, text, temperature, top_p, max_tokens):
|
44 |
"""LLaVA 模型推理"""
|