Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -19,19 +19,30 @@ import gradio as gr
|
|
19 |
import diffusers
|
20 |
import torch
|
21 |
|
22 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
def generate_image(prompt, guidance_scale, num_inference_steps):
|
24 |
-
# Load the model from the specified file
|
25 |
-
model = diffusers.StableDiffusionXLPipeline.from_pretrained(
|
26 |
-
"Liberata/illustrious-xl-v1.0",
|
27 |
-
torch_dtype=torch.float16
|
28 |
-
)
|
29 |
# Generate the image from the text prompt with the specified parameters
|
30 |
image = model(prompt, guidance_scale=guidance_scale, num_inference_steps=num_inference_steps).images[0]
|
31 |
return image
|
32 |
|
33 |
# Create a Gradio interface for the text-to-image generation
|
34 |
with gr.Blocks() as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
# Create a two-column layout
|
36 |
with gr.Row():
|
37 |
with gr.Column():
|
@@ -46,13 +57,6 @@ with gr.Blocks() as demo:
|
|
46 |
# Create an image output to display the generated image
|
47 |
image_output = gr.Image(label="Generated Image")
|
48 |
|
49 |
-
# Add some documentation using HTML
|
50 |
-
gr.HTML("""
|
51 |
-
<h2>Text-to-Image Generation with Liberata/illustrious-xl-v1.0</h2>
|
52 |
-
<p>This app allows you to generate images from text prompts using the Liberata/illustrious-xl-v1.0 model.</p>
|
53 |
-
<p>Simply enter a text prompt, adjust the parameters, and click the 'Generate Image' button to see the generated image.</p>
|
54 |
-
""")
|
55 |
-
|
56 |
# Create a button to trigger the image generation
|
57 |
generate_button = gr.Button("Generate Image")
|
58 |
|
@@ -61,6 +65,8 @@ with gr.Blocks() as demo:
|
|
61 |
|
62 |
# Add examples
|
63 |
examples = [
|
|
|
|
|
64 |
["A fox drinking tea under a cherry blossom tree, anime style, 4K resolution"],
|
65 |
["Night view of a futuristic city, cyberpunk style, neon lights"],
|
66 |
["Medieval knight battling a dragon, epic scene, oil painting texture"]
|
|
|
19 |
import diffusers
|
20 |
import torch
|
21 |
|
22 |
+
# Automatically detect if CUDA is available and set the device accordingly
|
23 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
24 |
+
|
25 |
+
# Load the model from the specified file outside the function to ensure better performance
|
26 |
+
model = diffusers.StableDiffusionXLPipeline.from_single_file(
|
27 |
+
"https://huggingface.co/Liberata/illustrious-xl-v1.0/blob/main/Illustrious-XL-v1.0.safetensors",
|
28 |
+
torch_dtype=torch.float16
|
29 |
+
).to(device) # Move the model to the detected device
|
30 |
+
|
31 |
+
# Define the function to generate an image from text using the pre-loaded model
|
32 |
def generate_image(prompt, guidance_scale, num_inference_steps):
|
|
|
|
|
|
|
|
|
|
|
33 |
# Generate the image from the text prompt with the specified parameters
|
34 |
image = model(prompt, guidance_scale=guidance_scale, num_inference_steps=num_inference_steps).images[0]
|
35 |
return image
|
36 |
|
37 |
# Create a Gradio interface for the text-to-image generation
|
38 |
with gr.Blocks() as demo:
|
39 |
+
# Add some documentation using HTML
|
40 |
+
gr.HTML("""
|
41 |
+
<h2> 😊 Text-to-Image Generation with Liberata/illustrious-xl-v1.0</h2>
|
42 |
+
<p>This app allows you to generate images from text prompts using the Liberata/illustrious-xl-v1.0 model.</p>
|
43 |
+
<p>Simply enter a text prompt, adjust the parameters, and click the 'Generate Image' button to see the generated image.</p>
|
44 |
+
""")
|
45 |
+
|
46 |
# Create a two-column layout
|
47 |
with gr.Row():
|
48 |
with gr.Column():
|
|
|
57 |
# Create an image output to display the generated image
|
58 |
image_output = gr.Image(label="Generated Image")
|
59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
# Create a button to trigger the image generation
|
61 |
generate_button = gr.Button("Generate Image")
|
62 |
|
|
|
65 |
|
66 |
# Add examples
|
67 |
examples = [
|
68 |
+
["1boy, Digital anime-style ALBEDO has light gray, messy hair, blue eyes. Shy look, in white & blue hoodie, at cozy café table with food. Shelf background"],
|
69 |
+
["1boy ,Digital anime-style CHONGYUN has shiny silver hair, green eyes. Cheerful expression, in bright blue T-shirt, at luxurious restaurant with Belgian chocolates. Elegant crystal chandelier background."],
|
70 |
["A fox drinking tea under a cherry blossom tree, anime style, 4K resolution"],
|
71 |
["Night view of a futuristic city, cyberpunk style, neon lights"],
|
72 |
["Medieval knight battling a dragon, epic scene, oil painting texture"]
|