sal-maq commited on
Commit
0ac60e4
·
verified ·
1 Parent(s): 90d20dc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -5
app.py CHANGED
@@ -7,7 +7,10 @@ import gradio as gr
7
  # Load the Stable Diffusion model
8
  model_id = "runwayml/stable-diffusion-v1-5"
9
  pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
10
- pipe = pipe.to("cuda")
 
 
 
11
 
12
  # Function to generate an image
13
  def generate_image(prompt):
@@ -16,8 +19,14 @@ def generate_image(prompt):
16
 
17
  # Define the Gradio interface
18
  with gr.Blocks() as demo:
19
- gr.Markdown("# 🌄 Generate Stunning Images with Stable Diffusion")
20
- gr.Markdown("### Type a prompt to create a beautiful image:")
 
 
 
 
 
 
21
 
22
  with gr.Row():
23
  with gr.Column():
@@ -28,7 +37,13 @@ with gr.Blocks() as demo:
28
 
29
  submit_button.click(fn=generate_image, inputs=prompt, outputs=image_output)
30
 
31
- gr.Markdown("#### Developed by Salman Maqbool ✨")
 
 
 
 
 
 
32
 
33
  # Launch the Gradio app
34
- demo.launch()
 
7
  # Load the Stable Diffusion model
8
  model_id = "runwayml/stable-diffusion-v1-5"
9
  pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
10
+
11
+ # Use CPU as fallback if CUDA is not available
12
+ device = "cuda" if torch.cuda.is_available() else "cpu"
13
+ pipe = pipe.to(device)
14
 
15
  # Function to generate an image
16
  def generate_image(prompt):
 
19
 
20
  # Define the Gradio interface
21
  with gr.Blocks() as demo:
22
+ gr.HTML(
23
+ """
24
+ <div style="text-align: center;">
25
+ <h1>🌄 Generate Stunning Images with Stable Diffusion</h1>
26
+ <h3>Type a prompt to create a beautiful image:</h3>
27
+ </div>
28
+ """
29
+ )
30
 
31
  with gr.Row():
32
  with gr.Column():
 
37
 
38
  submit_button.click(fn=generate_image, inputs=prompt, outputs=image_output)
39
 
40
+ gr.HTML(
41
+ """
42
+ <div style="text-align: center;">
43
+ <h4>Developed by Salman Maqbool ✨</h4>
44
+ </div>
45
+ """
46
+ )
47
 
48
  # Launch the Gradio app
49
+ demo.launch()