Spaces:
Running
on
Zero
Running
on
Zero
update app
Browse files
app.py
CHANGED
|
@@ -102,24 +102,6 @@ MAX_INPUT_TOKEN_LENGTH = int(os.getenv("MAX_INPUT_TOKEN_LENGTH", "4096"))
|
|
| 102 |
|
| 103 |
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
| 104 |
|
| 105 |
-
# Load Qwen2.5-VL-7B-Instruct
|
| 106 |
-
MODEL_ID_M = "Qwen/Qwen2.5-VL-7B-Instruct"
|
| 107 |
-
processor_m = AutoProcessor.from_pretrained(MODEL_ID_M, trust_remote_code=True)
|
| 108 |
-
model_m = Qwen2_5_VLForConditionalGeneration.from_pretrained(
|
| 109 |
-
MODEL_ID_M,
|
| 110 |
-
trust_remote_code=True,
|
| 111 |
-
torch_dtype=torch.float16
|
| 112 |
-
).to(device).eval()
|
| 113 |
-
|
| 114 |
-
# Load Qwen2.5-VL-3B-Instruct
|
| 115 |
-
MODEL_ID_X = "Qwen/Qwen2.5-VL-3B-Instruct"
|
| 116 |
-
processor_x = AutoProcessor.from_pretrained(MODEL_ID_X, trust_remote_code=True)
|
| 117 |
-
model_x = Qwen2_5_VLForConditionalGeneration.from_pretrained(
|
| 118 |
-
MODEL_ID_X,
|
| 119 |
-
trust_remote_code=True,
|
| 120 |
-
torch_dtype=torch.float16
|
| 121 |
-
).to(device).eval()
|
| 122 |
-
|
| 123 |
# Load Qwen3-VL-4B-Instruct
|
| 124 |
MODEL_ID_Q = "Qwen/Qwen3-VL-4B-Instruct"
|
| 125 |
processor_q = AutoProcessor.from_pretrained(MODEL_ID_Q, trust_remote_code=True)
|
|
@@ -179,11 +161,8 @@ def generate_image(model_name: str, text: str, image: Image.Image,
|
|
| 179 |
"""
|
| 180 |
Generates responses using the selected model for image input.
|
| 181 |
"""
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
elif model_name == "Qwen2.5-VL-3B-Instruct":
|
| 185 |
-
processor, model = processor_x, model_x
|
| 186 |
-
elif model_name == "Qwen3-VL-4B-Instruct":
|
| 187 |
processor, model = processor_q, model_q
|
| 188 |
elif model_name == "Qwen3-VL-8B-Instruct":
|
| 189 |
processor, model = processor_y, model_y
|
|
@@ -221,11 +200,7 @@ def generate_video(model_name: str, text: str, video_path: str,
|
|
| 221 |
"""
|
| 222 |
Generates responses using the selected model for video input.
|
| 223 |
"""
|
| 224 |
-
if model_name == "
|
| 225 |
-
processor, model = processor_m, model_m
|
| 226 |
-
elif model_name == "Qwen2.5-VL-3B-Instruct":
|
| 227 |
-
processor, model = processor_x, model_x
|
| 228 |
-
elif model_name == "Qwen3-VL-4B-Instruct":
|
| 229 |
processor, model = processor_q, model_q
|
| 230 |
elif model_name == "Qwen3-VL-8B-Instruct":
|
| 231 |
processor, model = processor_y, model_y
|
|
@@ -264,7 +239,7 @@ def generate_video(model_name: str, text: str, video_path: str,
|
|
| 264 |
buffer = ""
|
| 265 |
for new_text in streamer:
|
| 266 |
buffer += new_text
|
| 267 |
-
buffer = buffer.replace("<|im_end|>", "")
|
| 268 |
time.sleep(0.01)
|
| 269 |
yield buffer, buffer
|
| 270 |
|
|
@@ -325,9 +300,9 @@ with gr.Blocks(css=css, theme=steel_blue_theme) as demo:
|
|
| 325 |
markdown_output = gr.Markdown()
|
| 326 |
|
| 327 |
model_choice = gr.Radio(
|
| 328 |
-
choices=["Qwen3-VL-
|
| 329 |
label="Select Model",
|
| 330 |
-
value="
|
| 331 |
)
|
| 332 |
|
| 333 |
image_submit.click(
|
|
|
|
| 102 |
|
| 103 |
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
| 104 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
# Load Qwen3-VL-4B-Instruct
|
| 106 |
MODEL_ID_Q = "Qwen/Qwen3-VL-4B-Instruct"
|
| 107 |
processor_q = AutoProcessor.from_pretrained(MODEL_ID_Q, trust_remote_code=True)
|
|
|
|
| 161 |
"""
|
| 162 |
Generates responses using the selected model for image input.
|
| 163 |
"""
|
| 164 |
+
|
| 165 |
+
if model_name == "Qwen3-VL-4B-Instruct":
|
|
|
|
|
|
|
|
|
|
| 166 |
processor, model = processor_q, model_q
|
| 167 |
elif model_name == "Qwen3-VL-8B-Instruct":
|
| 168 |
processor, model = processor_y, model_y
|
|
|
|
| 200 |
"""
|
| 201 |
Generates responses using the selected model for video input.
|
| 202 |
"""
|
| 203 |
+
if model_name == "Qwen3-VL-4B-Instruct":
|
|
|
|
|
|
|
|
|
|
|
|
|
| 204 |
processor, model = processor_q, model_q
|
| 205 |
elif model_name == "Qwen3-VL-8B-Instruct":
|
| 206 |
processor, model = processor_y, model_y
|
|
|
|
| 239 |
buffer = ""
|
| 240 |
for new_text in streamer:
|
| 241 |
buffer += new_text
|
| 242 |
+
#buffer = buffer.replace("<|im_end|>", "")
|
| 243 |
time.sleep(0.01)
|
| 244 |
yield buffer, buffer
|
| 245 |
|
|
|
|
| 300 |
markdown_output = gr.Markdown()
|
| 301 |
|
| 302 |
model_choice = gr.Radio(
|
| 303 |
+
choices=["Qwen3-VL-4B-Instruct", "Qwen3-VL-2B-Instruct", "Qwen3-VL-8B-Instruct"],
|
| 304 |
label="Select Model",
|
| 305 |
+
value="Qwen3-VL-4B-Instruct"
|
| 306 |
)
|
| 307 |
|
| 308 |
image_submit.click(
|