Update app.py
Browse files
app.py
CHANGED
|
@@ -2,16 +2,14 @@ import gradio as gr
|
|
| 2 |
from diffusers import StableDiffusionPipeline
|
| 3 |
import torch
|
| 4 |
|
| 5 |
-
# Load
|
| 6 |
model_id = "runwayml/stable-diffusion-v1-5"
|
| 7 |
pipe = StableDiffusionPipeline.from_pretrained(
|
| 8 |
model_id,
|
| 9 |
-
torch_dtype=torch.float16
|
| 10 |
-
revision="fp16" # Uses less VRAM
|
| 11 |
).to("cuda")
|
| 12 |
|
| 13 |
def generate_image(prompt, negative_prompt="", steps=30, guidance_scale=7.5):
|
| 14 |
-
"""Generate an image from text with customizable settings."""
|
| 15 |
image = pipe(
|
| 16 |
prompt,
|
| 17 |
negative_prompt=negative_prompt,
|
|
@@ -20,23 +18,18 @@ def generate_image(prompt, negative_prompt="", steps=30, guidance_scale=7.5):
|
|
| 20 |
).images[0]
|
| 21 |
return image
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
gr.Markdown("## 🚀 Generate Images from Text")
|
| 26 |
with gr.Row():
|
| 27 |
with gr.Column():
|
| 28 |
-
prompt = gr.Textbox(label="
|
| 29 |
-
negative_prompt = gr.Textbox(label="
|
| 30 |
-
steps = gr.Slider(1, 50, value=30, label="
|
| 31 |
guidance = gr.Slider(1, 15, value=7.5, label="Guidance Scale")
|
| 32 |
submit = gr.Button("Generate")
|
| 33 |
with gr.Column():
|
| 34 |
-
output = gr.Image(label="
|
| 35 |
|
| 36 |
-
submit.click(
|
| 37 |
-
generate_image,
|
| 38 |
-
inputs=[prompt, negative_prompt, steps, guidance],
|
| 39 |
-
outputs=output
|
| 40 |
-
)
|
| 41 |
|
| 42 |
-
demo.launch(
|
|
|
|
| 2 |
from diffusers import StableDiffusionPipeline
|
| 3 |
import torch
|
| 4 |
|
| 5 |
+
# Load model without specifying fp16 revision
|
| 6 |
model_id = "runwayml/stable-diffusion-v1-5"
|
| 7 |
pipe = StableDiffusionPipeline.from_pretrained(
|
| 8 |
model_id,
|
| 9 |
+
torch_dtype=torch.float16 # Still use fp16 precision
|
|
|
|
| 10 |
).to("cuda")
|
| 11 |
|
| 12 |
def generate_image(prompt, negative_prompt="", steps=30, guidance_scale=7.5):
|
|
|
|
| 13 |
image = pipe(
|
| 14 |
prompt,
|
| 15 |
negative_prompt=negative_prompt,
|
|
|
|
| 18 |
).images[0]
|
| 19 |
return image
|
| 20 |
|
| 21 |
+
with gr.Blocks(title="RimageGen") as demo:
|
| 22 |
+
gr.Markdown("## 🎨 Text-to-Image Generator")
|
|
|
|
| 23 |
with gr.Row():
|
| 24 |
with gr.Column():
|
| 25 |
+
prompt = gr.Textbox(label="Prompt", placeholder="A cute corgi wearing a crown")
|
| 26 |
+
negative_prompt = gr.Textbox(label="Negative Prompt", placeholder="blurry, deformed")
|
| 27 |
+
steps = gr.Slider(1, 50, value=30, label="Steps")
|
| 28 |
guidance = gr.Slider(1, 15, value=7.5, label="Guidance Scale")
|
| 29 |
submit = gr.Button("Generate")
|
| 30 |
with gr.Column():
|
| 31 |
+
output = gr.Image(label="Result")
|
| 32 |
|
| 33 |
+
submit.click(generate_image, inputs=[prompt, negative_prompt, steps, guidance], outputs=output)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
+
demo.launch()
|