Spaces:
Running
on
Zero
Running
on
Zero
Commit
·
eaa703f
1
Parent(s):
259b8b5
zerogpu updates
Browse files
app.py
CHANGED
@@ -5,10 +5,12 @@ import gradio as gr
|
|
5 |
from PIL import Image
|
6 |
from transformers import Qwen2_5_VLForConditionalGeneration, AutoProcessor
|
7 |
from typing import List
|
|
|
8 |
|
9 |
MODEL_ID = "remyxai/SpaceThinker-Qwen2.5VL-3B"
|
10 |
|
11 |
@spaces.GPU
|
|
|
12 |
def load_model():
|
13 |
print("Loading model and processor...")
|
14 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
@@ -19,8 +21,6 @@ def load_model():
|
|
19 |
processor = AutoProcessor.from_pretrained(MODEL_ID)
|
20 |
return model, processor
|
21 |
|
22 |
-
model, processor = load_model()
|
23 |
-
|
24 |
def process_image(image_path_or_obj):
|
25 |
"""Loads, resizes, and preprocesses an image path or Pillow Image."""
|
26 |
if isinstance(image_path_or_obj, str):
|
@@ -73,6 +73,7 @@ def only_assistant_text(full_text: str) -> str:
|
|
73 |
return full_text.strip()
|
74 |
|
75 |
def run_inference(image, prompt):
|
|
|
76 |
"""Runs Qwen2.5-VL inference on a single image and text prompt."""
|
77 |
system_msg = (
|
78 |
"You are VL-Thinking 🤔, a helpful assistant with excellent reasoning ability. "
|
|
|
5 |
from PIL import Image
|
6 |
from transformers import Qwen2_5_VLForConditionalGeneration, AutoProcessor
|
7 |
from typing import List
|
8 |
+
from functools import lru_cache
|
9 |
|
10 |
MODEL_ID = "remyxai/SpaceThinker-Qwen2.5VL-3B"
|
11 |
|
12 |
@spaces.GPU
|
13 |
+
@lru_cache(maxsize=1)
|
14 |
def load_model():
|
15 |
print("Loading model and processor...")
|
16 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
|
21 |
processor = AutoProcessor.from_pretrained(MODEL_ID)
|
22 |
return model, processor
|
23 |
|
|
|
|
|
24 |
def process_image(image_path_or_obj):
|
25 |
"""Loads, resizes, and preprocesses an image path or Pillow Image."""
|
26 |
if isinstance(image_path_or_obj, str):
|
|
|
73 |
return full_text.strip()
|
74 |
|
75 |
def run_inference(image, prompt):
|
76 |
+
model, processor = load_model()
|
77 |
"""Runs Qwen2.5-VL inference on a single image and text prompt."""
|
78 |
system_msg = (
|
79 |
"You are VL-Thinking 🤔, a helpful assistant with excellent reasoning ability. "
|