Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,24 +1,11 @@
|
|
1 |
import gradio as gr
|
2 |
from diffusers import DiffusionPipeline
|
3 |
|
4 |
-
# Initialize the pipeline variable globally
|
5 |
-
pipeline = None
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
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
|
@@ -30,12 +17,9 @@ with gr.Blocks() as demo:
|
|
30 |
negative_prompt = gr.Textbox(label="Negative Prompt", placeholder="Enter your negative prompt here")
|
31 |
submit_button = gr.Button("Generate Image")
|
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)
|
39 |
|
40 |
# Launch the demo
|
41 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from diffusers import DiffusionPipeline
|
3 |
|
|
|
|
|
4 |
|
5 |
+
def generate_image(modelsyu, prompt, negative_prompt):
|
6 |
+
|
7 |
+
modelslo = [modelsyu]
|
8 |
+
pipeline = DiffusionPipeline.from_pretrained(modelslo)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
pipeline.to("cpu")
|
10 |
image = pipeline(prompt, negative_prompt=negative_prompt).images[0]
|
11 |
return image
|
|
|
17 |
negative_prompt = gr.Textbox(label="Negative Prompt", placeholder="Enter your negative prompt here")
|
18 |
submit_button = gr.Button("Generate Image")
|
19 |
with gr.Accordion('Load your custom models first'):
|
20 |
+
basem = gr.Textbox(label="Your Lora model", value="John6666/pony-diffusion-v6-xl-sdxl-spo")
|
|
|
|
|
|
|
21 |
output_image = gr.Image(label="Generated Image")
|
22 |
+
submit_button.click(generate_image, inputs=[basem, prompt, negative_prompt], outputs=output_image)
|
23 |
|
24 |
# Launch the demo
|
25 |
demo.launch()
|