File size: 1,569 Bytes
576d9f6
 
298faaa
 
576d9f6
 
 
 
 
 
 
 
 
 
 
298faaa
 
 
 
 
 
 
 
 
576d9f6
 
 
 
 
 
 
 
 
298faaa
576d9f6
 
298faaa
576d9f6
 
 
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
36
37
38
39
40
41
import requests
import gradio as gr
from PIL import Image
from io import BytesIO

def generate_image(prompt, size):
    headers = {
        "Content-Type": "application/json",
    }
    data = {
        "prompt": prompt,
        "model": "dall-e-3",
        "size": size,
        "num_images": 1,
    }
    response = requests.post("https://sdcf.dongsiqie.me", headers=headers, json=data)

    # Get image content from the response
    image_content = BytesIO(response.content)
    image = Image.open(image_content)

    # Save image to a file or return it in a suitable format for your context.
    # For this example, I'm going to return the image directly.
    return image

# Create the interface using Gradio
with gr.Blocks() as demo:
    with gr.Row():
        gr.Markdown("# <center>stable-diffusion-xl-base-1.0</center>")
        gr.Markdown("This demo uses the stable-diffusion-xl-base-1.0 API to generate an image from text.")
    with gr.Row():
        size_input = gr.Dropdown(label="Size", choices=["1792x1024", "1024x1024", "1024x1792"], value="1024x1024")
    with gr.Row():
        prompt_input = gr.Textbox(label="Image Description", value="A futuristic cyberpunk-style puppy, neon-lit cityscape background, glowing eyes, mechanized body parts, dynamic pose, vibrant colors, nighttime vibe, sharp focus, digital art.")
    submit_btn = gr.Button("Generate Image", variant='primary')
    image_output = gr.Image(label="Generated Image")
   
    submit_btn.click(fn=generate_image, inputs=[prompt_input, size_input], outputs=image_output)

demo.launch()