Update app.py
Browse filesStep 2: Add Real Image Generation with Stable Diffusion
app.py
CHANGED
|
@@ -1,18 +1,31 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
with gr.Blocks() as demo:
|
| 7 |
gr.Markdown("## 🎨 Welcome to MUSE – Your Visual Muse Generator")
|
| 8 |
|
| 9 |
with gr.Row():
|
| 10 |
-
prompt = gr.Textbox(label="Describe your idea", placeholder="e.g.
|
| 11 |
output_type = gr.Radio(["Image", "3D Model"], label="Choose output type", value="Image")
|
| 12 |
|
| 13 |
-
generate_button = gr.Button("Generate")
|
| 14 |
-
|
| 15 |
|
| 16 |
-
generate_button.click(fn=
|
| 17 |
|
| 18 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from diffusers import StableDiffusionPipeline
|
| 3 |
+
import torch
|
| 4 |
|
| 5 |
+
# Load model
|
| 6 |
+
pipe = StableDiffusionPipeline.from_pretrained(
|
| 7 |
+
"stabilityai/stable-diffusion-2-1",
|
| 8 |
+
torch_dtype=torch.float16,
|
| 9 |
+
revision="fp16"
|
| 10 |
+
).to("cuda")
|
| 11 |
+
|
| 12 |
+
def generate_muse(prompt, output_type):
|
| 13 |
+
if output_type == "Image":
|
| 14 |
+
image = pipe(prompt).images[0]
|
| 15 |
+
return image
|
| 16 |
+
else:
|
| 17 |
+
return "⚠️ 3D Model generation coming soon. Please select 'Image'."
|
| 18 |
|
| 19 |
with gr.Blocks() as demo:
|
| 20 |
gr.Markdown("## 🎨 Welcome to MUSE – Your Visual Muse Generator")
|
| 21 |
|
| 22 |
with gr.Row():
|
| 23 |
+
prompt = gr.Textbox(label="Describe your idea", placeholder="e.g. bamboo dome with fabric sails, inspired by jellyfish")
|
| 24 |
output_type = gr.Radio(["Image", "3D Model"], label="Choose output type", value="Image")
|
| 25 |
|
| 26 |
+
generate_button = gr.Button("Generate Muse")
|
| 27 |
+
image_output = gr.Image(label="Your Muse Output")
|
| 28 |
|
| 29 |
+
generate_button.click(fn=generate_muse, inputs=[prompt, output_type], outputs=image_output)
|
| 30 |
|
| 31 |
demo.launch()
|