akhaliq HF staff commited on
Commit
2539943
1 Parent(s): 3e7d42c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -11,7 +11,7 @@ def encode_image(img):
11
  buffered = BytesIO()
12
  img.save(buffered, format="PNG")
13
  encoded_string = base64.b64encode(buffered.getvalue()).decode("utf-8")
14
- return encoded_string
15
 
16
  def get_api_response(api_key, user_inputs):
17
  """
@@ -38,11 +38,11 @@ def get_api_response(api_key, user_inputs):
38
  })
39
 
40
  if user_inputs.get("image"):
41
- # Open the uploaded image (already a PIL Image)
42
  base64_img = encode_image(user_inputs["image"])
43
  messages.append({
44
  "type": "image_url",
45
- "image_url": {"url": f"data:image/png;base64,{base64_img}"}
46
  })
47
 
48
  payload = {
@@ -85,7 +85,9 @@ def chatbot_response(api_key, user_inputs, history):
85
  if user_text:
86
  user_content.append(user_text)
87
  if user_image:
88
- user_content.append(user_image)
 
 
89
 
90
  # Append the user's message to the history
91
  if user_content:
 
11
  buffered = BytesIO()
12
  img.save(buffered, format="PNG")
13
  encoded_string = base64.b64encode(buffered.getvalue()).decode("utf-8")
14
+ return f"data:image/png;base64,{encoded_string}"
15
 
16
  def get_api_response(api_key, user_inputs):
17
  """
 
38
  })
39
 
40
  if user_inputs.get("image"):
41
+ # Encode the uploaded image to a base64 string
42
  base64_img = encode_image(user_inputs["image"])
43
  messages.append({
44
  "type": "image_url",
45
+ "image_url": {"url": base64_img}
46
  })
47
 
48
  payload = {
 
85
  if user_text:
86
  user_content.append(user_text)
87
  if user_image:
88
+ # Convert the PIL Image to a base64 string
89
+ img_data = encode_image(user_image)
90
+ user_content.append(img_data)
91
 
92
  # Append the user's message to the history
93
  if user_content: