sagar007 commited on
Commit
6f27c43
·
verified ·
1 Parent(s): 231fb5f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -3
app.py CHANGED
@@ -80,11 +80,26 @@ def stream_text_chat(message, history, system_prompt, temperature=0.8, max_new_t
80
  buffer += new_text
81
  yield history + [[message, buffer]]
82
 
83
- @spaces.GPU # Add this decorator
84
  def process_vision_query(image, text_input):
85
  prompt = f"<|user|>\n<|image_1|>\n{text_input}<|end|>\n<|assistant|>\n"
86
- image = Image.fromarray(image).convert("RGB")
87
- inputs = vision_processor(prompt, image, return_tensors="pt").to(device)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
 
89
  with torch.no_grad():
90
  generate_ids = vision_model.generate(
 
80
  buffer += new_text
81
  yield history + [[message, buffer]]
82
 
83
+ @spaces.GPU
84
  def process_vision_query(image, text_input):
85
  prompt = f"<|user|>\n<|image_1|>\n{text_input}<|end|>\n<|assistant|>\n"
86
+
87
+ # Convert the image to bytes if it's not already
88
+ if isinstance(image, Image.Image):
89
+ # If it's a PIL Image, convert to bytes
90
+ import io
91
+ img_byte_arr = io.BytesIO()
92
+ image.save(img_byte_arr, format='PNG')
93
+ image = img_byte_arr.getvalue()
94
+ elif isinstance(image, np.ndarray):
95
+ # If it's a numpy array, convert to PIL Image first, then to bytes
96
+ image = Image.fromarray(image).convert("RGB")
97
+ img_byte_arr = io.BytesIO()
98
+ image.save(img_byte_arr, format='PNG')
99
+ image = img_byte_arr.getvalue()
100
+
101
+ # Now process the image bytes
102
+ inputs = vision_processor(prompt, images=image, return_tensors="pt").to(device)
103
 
104
  with torch.no_grad():
105
  generate_ids = vision_model.generate(