Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,8 @@ import os
|
|
3 |
from together import Together
|
4 |
import base64
|
5 |
from io import BytesIO
|
|
|
|
|
6 |
|
7 |
# Initialize the Together client
|
8 |
api_key = os.environ.get('TOGETHER_API_KEY')
|
@@ -19,6 +21,10 @@ def generate_gradio_app(image):
|
|
19 |
return "Error: TOGETHER_API_KEY not set or client initialization failed. Please check your API key."
|
20 |
|
21 |
try:
|
|
|
|
|
|
|
|
|
22 |
# Convert the image to base64
|
23 |
buffered = BytesIO()
|
24 |
image.save(buffered, format="PNG")
|
|
|
3 |
from together import Together
|
4 |
import base64
|
5 |
from io import BytesIO
|
6 |
+
from PIL import Image
|
7 |
+
import numpy as np
|
8 |
|
9 |
# Initialize the Together client
|
10 |
api_key = os.environ.get('TOGETHER_API_KEY')
|
|
|
21 |
return "Error: TOGETHER_API_KEY not set or client initialization failed. Please check your API key."
|
22 |
|
23 |
try:
|
24 |
+
# Convert numpy array to PIL Image
|
25 |
+
if isinstance(image, np.ndarray):
|
26 |
+
image = Image.fromarray(image.astype('uint8'), 'RGB')
|
27 |
+
|
28 |
# Convert the image to base64
|
29 |
buffered = BytesIO()
|
30 |
image.save(buffered, format="PNG")
|