dlaima commited on
Commit
ee8a4e6
·
verified ·
1 Parent(s): 659bfbb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -3
app.py CHANGED
@@ -3,7 +3,6 @@ import os
3
  import io
4
  from PIL import Image
5
  import requests
6
- import json
7
  import warnings
8
  import gradio as gr
9
 
@@ -31,11 +30,14 @@ def generate_caption(image):
31
  try:
32
  headers = {"Authorization": f"Bearer {hf_api_key}"}
33
 
34
- # Convert PIL image to binary stream
35
  buffered = io.BytesIO()
 
36
  image.save(buffered, format="JPEG")
37
  buffered.seek(0)
38
- files = {"inputs": ("image.jpg", buffered, "image/jpeg")}
 
 
39
 
40
  # Make the POST request to the endpoint
41
  response = requests.post(endpoint_url, headers=headers, files=files)
 
3
  import io
4
  from PIL import Image
5
  import requests
 
6
  import warnings
7
  import gradio as gr
8
 
 
30
  try:
31
  headers = {"Authorization": f"Bearer {hf_api_key}"}
32
 
33
+ # Convert the PIL image to a binary stream in JPEG format
34
  buffered = io.BytesIO()
35
+ image = image.convert("RGB") # Ensure the image is in RGB mode
36
  image.save(buffered, format="JPEG")
37
  buffered.seek(0)
38
+
39
+ # Create the appropriate payload for the API
40
+ files = {"file": ("image.jpg", buffered, "image/jpeg")}
41
 
42
  # Make the POST request to the endpoint
43
  response = requests.post(endpoint_url, headers=headers, files=files)