Hev832 commited on
Commit
045d91e
·
verified ·
1 Parent(s): 15fce5d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -5
app.py CHANGED
@@ -5,16 +5,21 @@ from diffusers import DiffusionPipeline
5
  pipeline = None
6
 
7
  # Load the pipeline and LoRA weights
8
- def load_cust(modelsyu):
 
 
9
  pipeline = DiffusionPipeline.from_pretrained(modelsyu)
10
- output_result = pipeline()
11
- return output_result
12
-
 
13
  def generate_image(prompt, negative_prompt):
14
  global pipeline
15
  # Generate the image with the provided prompts
16
  if pipeline is None:
17
  return "Pipeline not loaded. Please load the models first."
 
 
18
  image = pipeline(prompt, negative_prompt=negative_prompt).images[0]
19
  return image
20
 
@@ -27,7 +32,7 @@ with gr.Blocks() as demo:
27
  with gr.Accordion('Load your custom models first'):
28
  basem = gr.Textbox(label="Your Lora model")
29
  exports = gr.Button("Load your models")
30
- outputid = gr.Textbox(label="output", interactive=False)
31
  exports.click(load_cust, inputs=[basem], outputs=[outputid])
32
  output_image = gr.Image(label="Generated Image")
33
  submit_button.click(generate_image, inputs=[prompt, negative_prompt], outputs=output_image)
 
5
  pipeline = None
6
 
7
  # Load the pipeline and LoRA weights
8
+ def load_cust(modelsyu, progress=gr.Progress()):
9
+ progress(10.4, desc="loading your lora models...")
10
+ global pipeline
11
  pipeline = DiffusionPipeline.from_pretrained(modelsyu)
12
+ # Ensure the pipeline uses the CPU
13
+ pipeline.to("cpu")
14
+ return "Models loaded successfully"
15
+
16
  def generate_image(prompt, negative_prompt):
17
  global pipeline
18
  # Generate the image with the provided prompts
19
  if pipeline is None:
20
  return "Pipeline not loaded. Please load the models first."
21
+ # Make sure the pipeline is set to use the CPU
22
+ pipeline.to("cpu")
23
  image = pipeline(prompt, negative_prompt=negative_prompt).images[0]
24
  return image
25
 
 
32
  with gr.Accordion('Load your custom models first'):
33
  basem = gr.Textbox(label="Your Lora model")
34
  exports = gr.Button("Load your models")
35
+ outputid = gr.Textbox(label="Output", interactive=False)
36
  exports.click(load_cust, inputs=[basem], outputs=[outputid])
37
  output_image = gr.Image(label="Generated Image")
38
  submit_button.click(generate_image, inputs=[prompt, negative_prompt], outputs=output_image)