Update app.py
Browse files
app.py
CHANGED
@@ -20,11 +20,11 @@ OPENAI_API_KEY = os.getenv('OPENAI_API_KEY')
|
|
20 |
|
21 |
|
22 |
def encode_image_to_base64(image):
|
23 |
-
# If image is a tuple (
|
24 |
if isinstance(image, tuple):
|
25 |
-
image = image[0]
|
26 |
|
27 |
-
# If image is a numpy array, convert to PIL Image
|
28 |
if isinstance(image, np.ndarray):
|
29 |
image = Image.fromarray(image)
|
30 |
|
@@ -36,6 +36,7 @@ def encode_image_to_base64(image):
|
|
36 |
image.save(buffered, format="PNG")
|
37 |
return base64.b64encode(buffered.getvalue()).decode('utf-8')
|
38 |
|
|
|
39 |
def analyze_image(image):
|
40 |
client = OpenAI(api_key=OPENAI_API_KEY)
|
41 |
base64_image = encode_image_to_base64(image)
|
|
|
20 |
|
21 |
|
22 |
def encode_image_to_base64(image):
|
23 |
+
# If image is a tuple (e.g., Gradio input), take the first element
|
24 |
if isinstance(image, tuple):
|
25 |
+
image = image[0] # Extract the image from the tuple
|
26 |
|
27 |
+
# If image is a numpy array, convert it to a PIL Image
|
28 |
if isinstance(image, np.ndarray):
|
29 |
image = Image.fromarray(image)
|
30 |
|
|
|
36 |
image.save(buffered, format="PNG")
|
37 |
return base64.b64encode(buffered.getvalue()).decode('utf-8')
|
38 |
|
39 |
+
|
40 |
def analyze_image(image):
|
41 |
client = OpenAI(api_key=OPENAI_API_KEY)
|
42 |
base64_image = encode_image_to_base64(image)
|