Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
|
|
|
|
|
|
| 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)
|