dongsiqie commited on
Commit
298faaa
1 Parent(s): c82f81d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -9
app.py CHANGED
@@ -1,5 +1,7 @@
1
  import requests
2
  import gradio as gr
 
 
3
 
4
  def generate_image(prompt, size):
5
  headers = {
@@ -11,13 +13,15 @@ def generate_image(prompt, size):
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:
@@ -27,10 +31,10 @@ with gr.Blocks() as demo:
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="space warrior, beautiful, female, ultrarealistic, soft lighting")
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()
 
1
  import requests
2
  import gradio as gr
3
+ from PIL import Image
4
+ from io import BytesIO
5
 
6
  def generate_image(prompt, size):
7
  headers = {
 
13
  "size": size,
14
  "num_images": 1,
15
  }
16
+ response = requests.post("https://sdcf.dongsiqie.me", headers=headers, json=data)
17
+
18
+ # Get image content from the response
19
+ image_content = BytesIO(response.content)
20
+ image = Image.open(image_content)
21
+
22
+ # Save image to a file or return it in a suitable format for your context.
23
+ # For this example, I'm going to return the image directly.
24
+ return image
25
 
26
  # Create the interface using Gradio
27
  with gr.Blocks() as demo:
 
31
  with gr.Row():
32
  size_input = gr.Dropdown(label="Size", choices=["1792x1024", "1024x1024", "1024x1792"], value="1024x1024")
33
  with gr.Row():
34
+ 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.")
35
  submit_btn = gr.Button("Generate Image", variant='primary')
36
  image_output = gr.Image(label="Generated Image")
37
+
38
  submit_btn.click(fn=generate_image, inputs=[prompt_input, size_input], outputs=image_output)
39
 
40
  demo.launch()