Spaces:
Build error
Build error
File size: 1,112 Bytes
ee55365 06df236 46faf1c 06df236 46faf1c 06df236 ee55365 06df236 46faf1c 06df236 2bed7f7 46faf1c 34ec04f 46faf1c 34ec04f 46faf1c ee55365 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
import gradio as gr
import requests
import os
from PIL import Image
from io import BytesIO
api_key = os.getenv("HF_API_KEY")
api_url = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl-base-1.0"
headers = {"Authorization": f"Bearer {api_key}"}
def generate_image(prompt):
payload = {
"inputs": prompt
}
response = requests.post(api_url, headers=headers, json=payload)
if response.status_code == 200:
# If the response is successful, return the image
image = response.content
return Image.open(BytesIO(response.content))
else:
print(response.text)
return "Error: " + response.text
iface = gr.Interface(fn=generate_image,
inputs=gr.Textbox(label="Enter your prompt", placeholder="Type your prompt here..."),
outputs="image",
live=False,
flagging_mode="never",
title="Stable Diffusion Image Generator",
description="Using State of the Art Stable Diffusion model")
iface.launch()
|