prithivMLmods commited on
Commit
83c8eb3
·
verified ·
1 Parent(s): 38b4e1b

update app

Browse files
Files changed (1) hide show
  1. app.py +30 -18
app.py CHANGED
@@ -102,6 +102,24 @@ 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 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)
@@ -120,15 +138,6 @@ model_y = Qwen3VLForConditionalGeneration.from_pretrained(
120
  torch_dtype=torch.float16
121
  ).to(device).eval()
122
 
123
- # Load Qwen3-VL-2B-Instruct
124
- MODEL_ID_L = "Qwen/Qwen3-VL-2B-Instruct"
125
- processor_l = AutoProcessor.from_pretrained(MODEL_ID_L, trust_remote_code=True)
126
- model_l = Qwen3VLForConditionalGeneration.from_pretrained(
127
- MODEL_ID_L,
128
- trust_remote_code=True,
129
- torch_dtype=torch.float16
130
- ).to(device).eval()
131
-
132
  def downsample_video(video_path):
133
  """
134
  Downsamples the video to evenly spaced frames.
@@ -161,13 +170,14 @@ def generate_image(model_name: str, text: str, image: Image.Image,
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
169
- elif model_name == "Qwen3-VL-2B-Instruct":
170
- processor, model = processor_l, model_l
171
  else:
172
  yield "Invalid model selected.", "Invalid model selected."
173
  return
@@ -200,12 +210,14 @@ def generate_video(model_name: str, text: str, video_path: str,
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
207
- elif model_name == "Qwen3-VL-2B-Instruct":
208
- processor, model = processor_l, model_l
209
  else:
210
  yield "Invalid model selected.", "Invalid model selected."
211
  return
@@ -295,12 +307,12 @@ with gr.Blocks(css=css, theme=steel_blue_theme) as demo:
295
 
296
  with gr.Column(scale=3):
297
  gr.Markdown("## Output", elem_id="output-title")
298
- output = gr.Textbox(label="Raw Output Stream", interactive=False, lines=11, show_copy_button=True)
299
  with gr.Accordion("(Result.md)", open=False):
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
  )
 
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)
 
138
  torch_dtype=torch.float16
139
  ).to(device).eval()
140
 
 
 
 
 
 
 
 
 
 
141
  def downsample_video(video_path):
142
  """
143
  Downsamples the video to evenly spaced frames.
 
170
  """
171
  Generates responses using the selected model for image input.
172
  """
173
+ if model_name == "Qwen2.5-VL-7B-Instruct":
174
+ processor, model = processor_m, model_m
175
+ elif model_name == "Qwen2.5-VL-3B-Instruct":
176
+ processor, model = processor_x, model_x
177
+ elif model_name == "Qwen3-VL-4B-Instruct":
178
  processor, model = processor_q, model_q
179
  elif model_name == "Qwen3-VL-8B-Instruct":
180
  processor, model = processor_y, model_y
 
 
181
  else:
182
  yield "Invalid model selected.", "Invalid model selected."
183
  return
 
210
  """
211
  Generates responses using the selected model for video input.
212
  """
213
+ if model_name == "Qwen2.5-VL-7B-Instruct":
214
+ processor, model = processor_m, model_m
215
+ elif model_name == "Qwen2.5-VL-3B-Instruct":
216
+ processor, model = processor_x, model_x
217
+ elif model_name == "Qwen3-VL-4B-Instruct":
218
  processor, model = processor_q, model_q
219
  elif model_name == "Qwen3-VL-8B-Instruct":
220
  processor, model = processor_y, model_y
 
 
221
  else:
222
  yield "Invalid model selected.", "Invalid model selected."
223
  return
 
307
 
308
  with gr.Column(scale=3):
309
  gr.Markdown("## Output", elem_id="output-title")
310
+ output = gr.Textbox(label="Raw Output Stream", interactive=False, lines=14, show_copy_button=True)
311
  with gr.Accordion("(Result.md)", open=False):
312
  markdown_output = gr.Markdown()
313
 
314
  model_choice = gr.Radio(
315
+ choices=["Qwen3-VL-4B-Instruct", "Qwen3-VL-8B-Instruct", "Qwen2.5-VL-3B-Instruct", "Qwen2.5-VL-7B-Instruct"],
316
  label="Select Model",
317
  value="Qwen3-VL-4B-Instruct"
318
  )