Daniton commited on
Commit
481192f
Β·
1 Parent(s): a385fc2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -6
app.py CHANGED
@@ -1,21 +1,23 @@
1
  import gradio as gr
2
  from diffusers import StableDiffusionPipeline
3
  import torch
4
- import random
5
 
6
  model_id = "nitrosocke/mo-di-diffusion"
7
- pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
8
- pipe = pipe.to("cpu")
 
 
 
 
 
9
 
10
  def generate_image(prompt):
11
- random.seed(42) # set seed for reproducibility
12
- prompt = f"modern disney style, {prompt}, seed={random.randint(0, 100000)}"
13
  image = pipe(prompt).images[0]
14
  image.save("./magical_princess.png")
15
  return image
16
 
17
  inputs = gr.inputs.Textbox(label="Enter Prompt")
18
- outputs = gr.outputs.Image(label="Generated Image")
19
 
20
  title = "Midjourney-Disney"
21
  description = None
 
1
  import gradio as gr
2
  from diffusers import StableDiffusionPipeline
3
  import torch
 
4
 
5
  model_id = "nitrosocke/mo-di-diffusion"
6
+ local_dir = "./model/"
7
+
8
+ # Download the model from the internet and save it to local directory
9
+ pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16, cache_dir=local_dir)
10
+
11
+ # Load the model from the local directory on subsequent runs
12
+ pipe = StableDiffusionPipeline.from_pretrained(local_dir, torch_dtype=torch.float16)
13
 
14
  def generate_image(prompt):
 
 
15
  image = pipe(prompt).images[0]
16
  image.save("./magical_princess.png")
17
  return image
18
 
19
  inputs = gr.inputs.Textbox(label="Enter Prompt")
20
+ outputs = gr.outputs.Image(label="Generated Image", type="pil")
21
 
22
  title = "Midjourney-Disney"
23
  description = None