sagar007 commited on
Commit
7877f6d
·
verified ·
1 Parent(s): 45cb2fc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -13
app.py CHANGED
@@ -85,21 +85,14 @@ def stream_text_chat(message, history, system_prompt, temperature=0.8, max_new_t
85
  def process_vision_query(image, text_input):
86
  prompt = f"<|user|>\n<|image_1|>\n{text_input}<|end|>\n<|assistant|>\n"
87
 
88
- # Convert the image to bytes if it's not already
89
- if isinstance(image, Image.Image):
90
- # If it's a PIL Image, convert to bytes
91
- import io
92
- img_byte_arr = io.BytesIO()
93
- image.save(img_byte_arr, format='PNG')
94
- image = img_byte_arr.getvalue()
95
- elif isinstance(image, np.ndarray):
96
- # If it's a numpy array, convert to PIL Image first, then to bytes
97
  image = Image.fromarray(image).convert("RGB")
98
- img_byte_arr = io.BytesIO()
99
- image.save(img_byte_arr, format='PNG')
100
- image = img_byte_arr.getvalue()
101
 
102
- # Now process the image bytes
103
  inputs = vision_processor(prompt, images=image, return_tensors="pt").to(device)
104
 
105
  with torch.no_grad():
 
85
  def process_vision_query(image, text_input):
86
  prompt = f"<|user|>\n<|image_1|>\n{text_input}<|end|>\n<|assistant|>\n"
87
 
88
+ # Ensure the image is in the correct format
89
+ if isinstance(image, np.ndarray):
90
+ # Convert numpy array to PIL Image
 
 
 
 
 
 
91
  image = Image.fromarray(image).convert("RGB")
92
+ elif not isinstance(image, Image.Image):
93
+ raise ValueError("Invalid image type. Expected PIL.Image.Image or numpy.ndarray")
 
94
 
95
+ # Now process the image
96
  inputs = vision_processor(prompt, images=image, return_tensors="pt").to(device)
97
 
98
  with torch.no_grad():