Spaces:
Build error
Build error
Commit
·
438e70b
1
Parent(s):
3c02b31
Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
-
import base64
|
4 |
-
from PIL import Image
|
5 |
-
from io import BytesIO
|
6 |
|
|
|
7 |
def generate_image(content, style):
|
8 |
headers = {
|
9 |
'Authorization': 'Bearer ZZUIQ4OZASNRQ8B8WYHNW',
|
@@ -14,20 +12,21 @@ def generate_image(content, style):
|
|
14 |
}
|
15 |
response = requests.post('https://api.fliki.ai/v1/generate/text-to-image', headers=headers, json=json_data)
|
16 |
|
17 |
-
#
|
18 |
-
|
19 |
-
|
20 |
-
image = Image.open(BytesIO(base64.b64decode(image_data)))
|
21 |
-
return image
|
22 |
-
else:
|
23 |
-
return "Error: No image returned"
|
24 |
|
|
|
|
|
|
|
|
|
25 |
iface = gr.Interface(
|
26 |
fn=generate_image,
|
27 |
inputs=[gr.Textbox(label="Content"), gr.Textbox(label="Style")],
|
28 |
-
outputs="
|
29 |
title="Text to Image Generator",
|
30 |
description="Enter a description and style to generate an image."
|
31 |
)
|
32 |
|
|
|
33 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import requests
|
|
|
|
|
|
|
3 |
|
4 |
+
# Function to call the API and generate the image
|
5 |
def generate_image(content, style):
|
6 |
headers = {
|
7 |
'Authorization': 'Bearer ZZUIQ4OZASNRQ8B8WYHNW',
|
|
|
12 |
}
|
13 |
response = requests.post('https://api.fliki.ai/v1/generate/text-to-image', headers=headers, json=json_data)
|
14 |
|
15 |
+
# Handle the response here based on the API's response format
|
16 |
+
# If the response is a URL:
|
17 |
+
# return response.json()['url']
|
|
|
|
|
|
|
|
|
18 |
|
19 |
+
# If the response is binary data:
|
20 |
+
return response.content
|
21 |
+
|
22 |
+
# Define the Gradio interface
|
23 |
iface = gr.Interface(
|
24 |
fn=generate_image,
|
25 |
inputs=[gr.Textbox(label="Content"), gr.Textbox(label="Style")],
|
26 |
+
outputs=gr.Image(type="auto"), # 'auto' will automatically handle URLs or binary data
|
27 |
title="Text to Image Generator",
|
28 |
description="Enter a description and style to generate an image."
|
29 |
)
|
30 |
|
31 |
+
# Launch the interface
|
32 |
iface.launch()
|