whyumesh commited on
Commit
124292b
·
verified ·
1 Parent(s): 5c690f1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -4
app.py CHANGED
@@ -10,8 +10,8 @@ import os
10
  def load_model():
11
  model = Qwen2VLForConditionalGeneration.from_pretrained(
12
  "Qwen/Qwen2-VL-2B-Instruct",
13
- torch_dtype=torch.float32
14
- )
15
  processor = AutoProcessor.from_pretrained("Qwen/Qwen2-VL-2B-Instruct")
16
  return model, processor
17
 
@@ -103,9 +103,10 @@ def generate_response(messages):
103
  videos=video_inputs,
104
  padding=True,
105
  return_tensors="pt",
106
- )
107
 
108
  del image_inputs, video_inputs
 
109
 
110
  with torch.no_grad():
111
  generated_ids = model.generate(**inputs, max_new_tokens=512) # Increased token limit for more detailed responses
@@ -130,4 +131,4 @@ iface = gr.Interface(
130
  description="Upload an image or video of code, diagrams, or technical content. Ask questions about bugs, errors, or explanations of functions.",
131
  )
132
 
133
- iface.launch()
 
10
  def load_model():
11
  model = Qwen2VLForConditionalGeneration.from_pretrained(
12
  "Qwen/Qwen2-VL-2B-Instruct",
13
+ torch_dtype=torch.float16
14
+ ).to("cuda")
15
  processor = AutoProcessor.from_pretrained("Qwen/Qwen2-VL-2B-Instruct")
16
  return model, processor
17
 
 
103
  videos=video_inputs,
104
  padding=True,
105
  return_tensors="pt",
106
+ ).to("cuda")
107
 
108
  del image_inputs, video_inputs
109
+ torch.cuda.empty_cache()
110
 
111
  with torch.no_grad():
112
  generated_ids = model.generate(**inputs, max_new_tokens=512) # Increased token limit for more detailed responses
 
131
  description="Upload an image or video of code, diagrams, or technical content. Ask questions about bugs, errors, or explanations of functions.",
132
  )
133
 
134
+ iface.launch(share=True)