Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +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 query_hf_image_generation(api_key, prompt):
|
|
@@ -19,20 +19,21 @@ def query_hf_image_generation(api_key, prompt):
|
|
| 19 |
|
| 20 |
# Check if the API response contains an error.
|
| 21 |
if 'error' in result:
|
| 22 |
-
return
|
| 23 |
|
| 24 |
# Assuming the API returns an image in base64 format.
|
| 25 |
-
image_data = result['data'][0] #
|
| 26 |
-
|
|
|
|
| 27 |
return image
|
| 28 |
|
| 29 |
iface = gr.Interface(
|
| 30 |
fn=query_hf_image_generation,
|
| 31 |
inputs=[
|
| 32 |
gr.Textbox(label="Hugging Face API Key", placeholder="Enter your Hugging Face API Key here..."),
|
| 33 |
-
gr.Textbox(lines=2, placeholder="Enter your prompt here...", label="Prompt")
|
| 34 |
],
|
| 35 |
-
outputs=gr.
|
| 36 |
title="Stable Diffusion XL Image Generator",
|
| 37 |
description="Enter your API Key and a prompt to generate an image using the Stable Diffusion XL model from Hugging Face."
|
| 38 |
)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
|
|
|
| 3 |
from PIL import Image
|
| 4 |
+
import base64
|
| 5 |
from io import BytesIO
|
| 6 |
|
| 7 |
def query_hf_image_generation(api_key, prompt):
|
|
|
|
| 19 |
|
| 20 |
# Check if the API response contains an error.
|
| 21 |
if 'error' in result:
|
| 22 |
+
return "Error: " + result['error'], None
|
| 23 |
|
| 24 |
# Assuming the API returns an image in base64 format.
|
| 25 |
+
image_data = result['data'][0] # Adjust this according to your specific API response structure
|
| 26 |
+
image_bytes = base64.b64decode(image_data.split(",")[1])
|
| 27 |
+
image = Image.open(BytesIO(image_bytes))
|
| 28 |
return image
|
| 29 |
|
| 30 |
iface = gr.Interface(
|
| 31 |
fn=query_hf_image_generation,
|
| 32 |
inputs=[
|
| 33 |
gr.Textbox(label="Hugging Face API Key", placeholder="Enter your Hugging Face API Key here..."),
|
| 34 |
+
gr.Textbox(lines=2, placeholder="Enter your prompt here...", label="Prompt")
|
| 35 |
],
|
| 36 |
+
outputs=gr.Image(label="Generated Image"),
|
| 37 |
title="Stable Diffusion XL Image Generator",
|
| 38 |
description="Enter your API Key and a prompt to generate an image using the Stable Diffusion XL model from Hugging Face."
|
| 39 |
)
|