Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import torch
|
| 3 |
+
from diffusers.pipelines import StableDiffusionPipeline
|
| 4 |
+
|
| 5 |
+
pipe = StableDiffusionPipeline.from_pretrained(
|
| 6 |
+
"runwayml/stable-diffusion-v1-5",
|
| 7 |
+
safety_checker=None,
|
| 8 |
+
torch_dtype=torch.float16,
|
| 9 |
+
use_safetensors=True,
|
| 10 |
+
).to("cuda")
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def generate_image(text):
|
| 14 |
+
image = pipe(text).images[0]
|
| 15 |
+
return image
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def generate_output(input_text):
|
| 19 |
+
# Generate the output image
|
| 20 |
+
output_image = generate_image(input_text)
|
| 21 |
+
return output_image
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
with gr.Blocks() as demo:
|
| 25 |
+
|
| 26 |
+
with gr.Row():
|
| 27 |
+
inputs = gr.Textbox(value="A cat", label="Enter your prompt here!")
|
| 28 |
+
btn_submit = gr.Button(value="Generate Image")
|
| 29 |
+
with gr.Row():
|
| 30 |
+
outputs = gr.Image(label="Generated Image")
|
| 31 |
+
btn_submit.click(generate_output, inputs, outputs)
|
| 32 |
+
|
| 33 |
+
demo.launch()
|