Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,8 @@
|
|
1 |
# Create a text-to-image interface with options to choose schedulers, sampling steps, and no default dark theme.
|
2 |
import gradio as gr
|
3 |
import numpy as np
|
4 |
-
|
5 |
import time
|
6 |
-
import os
|
7 |
|
8 |
# Define a function to generate an image based on the input text, scheduler, and sampling steps.
|
9 |
def generate_image(text, scheduler, sampling_steps):
|
@@ -20,12 +19,13 @@ def generate_image(text, scheduler, sampling_steps):
|
|
20 |
elif scheduler == "Euler":
|
21 |
image = np.clip(image * (1 + sampling_steps / 20), 0, 1)
|
22 |
|
23 |
-
# Generate a unique filename for the image
|
24 |
timestamp = int(time.time() * 1000)
|
25 |
filename = f"image_{timestamp}.webp"
|
26 |
|
27 |
-
#
|
28 |
-
|
|
|
29 |
|
30 |
return filename
|
31 |
|
@@ -51,4 +51,6 @@ with gr.Blocks() as demo:
|
|
51 |
if __name__ == "__main__":
|
52 |
gr.load("models/stabilityai/stable-diffusion-3.5-large").launch()
|
53 |
demo.launch(show_error=True)
|
|
|
|
|
54 |
|
|
|
1 |
# Create a text-to-image interface with options to choose schedulers, sampling steps, and no default dark theme.
|
2 |
import gradio as gr
|
3 |
import numpy as np
|
4 |
+
from PIL import Image
|
5 |
import time
|
|
|
6 |
|
7 |
# Define a function to generate an image based on the input text, scheduler, and sampling steps.
|
8 |
def generate_image(text, scheduler, sampling_steps):
|
|
|
19 |
elif scheduler == "Euler":
|
20 |
image = np.clip(image * (1 + sampling_steps / 20), 0, 1)
|
21 |
|
22 |
+
# Generate a unique filename for the image using the current timestamp
|
23 |
timestamp = int(time.time() * 1000)
|
24 |
filename = f"image_{timestamp}.webp"
|
25 |
|
26 |
+
# Convert the numpy array to a PIL image and save it in WEBP format
|
27 |
+
image_pil = Image.fromarray((image * 255).astype(np.uint8))
|
28 |
+
image_pil.save(filename, format="WEBP")
|
29 |
|
30 |
return filename
|
31 |
|
|
|
51 |
if __name__ == "__main__":
|
52 |
gr.load("models/stabilityai/stable-diffusion-3.5-large").launch()
|
53 |
demo.launch(show_error=True)
|
54 |
+
|
55 |
+
|
56 |
|