Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
def generate_image(prompt, size):
|
5 |
+
headers = {
|
6 |
+
"Content-Type": "application/json",
|
7 |
+
}
|
8 |
+
data = {
|
9 |
+
"prompt": prompt,
|
10 |
+
"model": "dall-e-3",
|
11 |
+
"size": size,
|
12 |
+
"num_images": 1,
|
13 |
+
}
|
14 |
+
response = requests.post("https://dalle3.dongsiqie.me", headers=headers, json=data)
|
15 |
+
response_json = response.json()
|
16 |
+
|
17 |
+
# Get the URL of the first generated image
|
18 |
+
image_url = response_json["data"][0]["url"]
|
19 |
+
|
20 |
+
return image_url
|
21 |
+
|
22 |
+
# Create the interface using Gradio
|
23 |
+
with gr.Blocks() as demo:
|
24 |
+
with gr.Row():
|
25 |
+
gr.Markdown("# <center>stable-diffusion-xl-base-1.0</center>")
|
26 |
+
gr.Markdown("This demo uses the stable-diffusion-xl-base-1.0 API to generate an image from text.")
|
27 |
+
with gr.Row():
|
28 |
+
size_input = gr.Dropdown(label="Size", choices=["1792x1024", "1024x1024", "1024x1792"], value="1024x1024")
|
29 |
+
with gr.Row():
|
30 |
+
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.")
|
31 |
+
submit_btn = gr.Button("Generate Image", variant='primary')
|
32 |
+
image_output = gr.Image(label="Generated Image")
|
33 |
+
|
34 |
+
submit_btn.click(fn=generate_image, inputs=[prompt_input, size_input], outputs=image_output)
|
35 |
+
|
36 |
+
demo.launch()
|