Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
@@ -1,13 +1,13 @@
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
import os
|
4 |
-
|
|
|
5 |
api_key = os.getenv("HF_API_KEY")
|
6 |
-
|
7 |
api_url = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl-base-1.0"
|
8 |
headers = {"Authorization": f"Bearer {api_key}"}
|
9 |
|
10 |
-
# Define the inference function using the Hugging Face API
|
11 |
def generate_image(prompt):
|
12 |
payload = {
|
13 |
"inputs": prompt
|
@@ -17,17 +17,18 @@ def generate_image(prompt):
|
|
17 |
if response.status_code == 200:
|
18 |
# If the response is successful, return the image
|
19 |
image = response.content
|
20 |
-
return
|
21 |
else:
|
22 |
print(response.text)
|
23 |
return "Error: " + response.text
|
24 |
-
|
25 |
iface = gr.Interface(fn=generate_image,
|
26 |
inputs=gr.Textbox(label="Enter your prompt", placeholder="Type your prompt here..."),
|
27 |
outputs="image",
|
28 |
-
live=False,
|
|
|
29 |
title="Stable Diffusion Image Generator",
|
30 |
-
description="
|
|
|
31 |
|
32 |
-
# Launch the Gradio app
|
33 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
import os
|
4 |
+
from PIL import Image
|
5 |
+
from io import BytesIO
|
6 |
api_key = os.getenv("HF_API_KEY")
|
7 |
+
|
8 |
api_url = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl-base-1.0"
|
9 |
headers = {"Authorization": f"Bearer {api_key}"}
|
10 |
|
|
|
11 |
def generate_image(prompt):
|
12 |
payload = {
|
13 |
"inputs": prompt
|
|
|
17 |
if response.status_code == 200:
|
18 |
# If the response is successful, return the image
|
19 |
image = response.content
|
20 |
+
return Image.open(BytesIO(response.content))
|
21 |
else:
|
22 |
print(response.text)
|
23 |
return "Error: " + response.text
|
24 |
+
|
25 |
iface = gr.Interface(fn=generate_image,
|
26 |
inputs=gr.Textbox(label="Enter your prompt", placeholder="Type your prompt here..."),
|
27 |
outputs="image",
|
28 |
+
live=False,
|
29 |
+
flagging_mode="never",
|
30 |
title="Stable Diffusion Image Generator",
|
31 |
+
description="Using State of the Art Stable Diffusion model")
|
32 |
+
|
33 |
|
|
|
34 |
iface.launch()
|