Spaces:
Sleeping
Sleeping
File size: 875 Bytes
6a47968 b5bf811 6a47968 |
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 |
from openai import OpenAI
import gradio as gr
import requests
from PIL import Image
from io import BytesIO
import os
client = OpenAI(base_url=os.environ['BASE_URL'], api_key=os.environ['API_KEY'])
def generate(prompt):
response = client.images.generate(
model="sdxl-lightning-4step",
prompt=prompt
)
imagebytes = requests.get(response.data[0].url)
image = Image.open(BytesIO(imagebytes.content))
return image
with gr.Blocks() as demo:
gr.Markdown("## SDXL Lightning Image Generator")
with gr.Row(equal_height=True):
promptbox = gr.Textbox(label="Prompt", placeholder="Enter your prompt")
generatebtn = gr.Button(value="Generate", variant="primary")
outputimg = gr.Image(width=1024, height=512)
generatebtn.click(
fn=generate,
inputs=promptbox,
outputs=outputimg
)
demo.launch() |