yukee1992 commited on
Commit
86f1f64
·
verified ·
1 Parent(s): d8164b3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -8
app.py CHANGED
@@ -4,7 +4,8 @@ from diffusers import StableDiffusionPipeline, EulerAncestralDiscreteScheduler
4
  import gradio as gr
5
  from PIL import Image
6
  import io
7
- import base64
 
8
  import time
9
 
10
  # Force CPU usage
@@ -76,14 +77,14 @@ def generate_image(prompt):
76
 
77
  print("Image generated successfully!")
78
 
79
- # SOLUTION: Convert image to bytes and return as file
80
- img_bytes = io.BytesIO()
81
- image.save(img_bytes, format='PNG')
82
- img_bytes.seek(0)
83
 
84
- return img_bytes
85
 
86
- # Create the Gradio Interface - CHANGE OUTPUT TO "file"
87
  demo = gr.Interface(
88
  fn=generate_image,
89
  inputs=gr.Textbox(
@@ -91,7 +92,7 @@ demo = gr.Interface(
91
  lines=2,
92
  placeholder="A dragon reading a book under a magical tree"
93
  ),
94
- outputs=gr.File(label="Download Generated Illustration"), # Changed to File output
95
  title="Premium Children's Book Illustrator 🤖🎨",
96
  description="Generating high-quality, sharp, detailed images for your stories. Enter a scene description."
97
  )
 
4
  import gradio as gr
5
  from PIL import Image
6
  import io
7
+ import tempfile
8
+ import os
9
  import time
10
 
11
  # Force CPU usage
 
77
 
78
  print("Image generated successfully!")
79
 
80
+ # Create a temporary file and save the image
81
+ with tempfile.NamedTemporaryFile(delete=False, suffix='.png') as tmp_file:
82
+ image.save(tmp_file, format='PNG')
83
+ tmp_file_path = tmp_file.name
84
 
85
+ return tmp_file_path
86
 
87
+ # Create the Gradio Interface
88
  demo = gr.Interface(
89
  fn=generate_image,
90
  inputs=gr.Textbox(
 
92
  lines=2,
93
  placeholder="A dragon reading a book under a magical tree"
94
  ),
95
+ outputs=gr.File(label="Download Generated Illustration"),
96
  title="Premium Children's Book Illustrator 🤖🎨",
97
  description="Generating high-quality, sharp, detailed images for your stories. Enter a scene description."
98
  )