Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -9,14 +9,15 @@ import torch
|
|
9 |
MODEL_NAME = "runwayml/stable-diffusion-v1-5"
|
10 |
OUTPUT_DIR = "/content/stable_diffusion_weights/custom_model"
|
11 |
|
12 |
-
def fine_tune(instance_prompt,
|
13 |
instance_data_dir = "/content/instance_images"
|
14 |
if os.path.exists(instance_data_dir):
|
15 |
shutil.rmtree(instance_data_dir)
|
16 |
os.makedirs(instance_data_dir, exist_ok=True)
|
17 |
|
18 |
-
|
19 |
-
|
|
|
20 |
|
21 |
fine_tune_model(instance_data_dir, instance_prompt, MODEL_NAME, OUTPUT_DIR)
|
22 |
return "Model fine-tuning complete."
|
@@ -40,10 +41,11 @@ def gradio_app():
|
|
40 |
with gr.Row():
|
41 |
with gr.Column():
|
42 |
instance_prompt = gr.Textbox(label="Instance Prompt")
|
43 |
-
|
|
|
44 |
fine_tune_button = gr.Button("Fine-Tune Model")
|
45 |
output_text = gr.Textbox(label="Output")
|
46 |
-
fine_tune_button.click(fine_tune, inputs=[instance_prompt,
|
47 |
|
48 |
with gr.Tab("Generate Images"):
|
49 |
with gr.Row():
|
@@ -62,4 +64,4 @@ def gradio_app():
|
|
62 |
demo.launch()
|
63 |
|
64 |
if __name__ == "__main__":
|
65 |
-
gradio_app()
|
|
|
9 |
MODEL_NAME = "runwayml/stable-diffusion-v1-5"
|
10 |
OUTPUT_DIR = "/content/stable_diffusion_weights/custom_model"
|
11 |
|
12 |
+
def fine_tune(instance_prompt, image1, image2=None):
|
13 |
instance_data_dir = "/content/instance_images"
|
14 |
if os.path.exists(instance_data_dir):
|
15 |
shutil.rmtree(instance_data_dir)
|
16 |
os.makedirs(instance_data_dir, exist_ok=True)
|
17 |
|
18 |
+
image1.save(os.path.join(instance_data_dir, "instance_0.png"))
|
19 |
+
if image2:
|
20 |
+
image2.save(os.path.join(instance_data_dir, "instance_1.png"))
|
21 |
|
22 |
fine_tune_model(instance_data_dir, instance_prompt, MODEL_NAME, OUTPUT_DIR)
|
23 |
return "Model fine-tuning complete."
|
|
|
41 |
with gr.Row():
|
42 |
with gr.Column():
|
43 |
instance_prompt = gr.Textbox(label="Instance Prompt")
|
44 |
+
image1 = gr.Image(label="Upload Image 1", type="pil")
|
45 |
+
image2 = gr.Image(label="Upload Image 2 (Optional)", type="pil", optional=True)
|
46 |
fine_tune_button = gr.Button("Fine-Tune Model")
|
47 |
output_text = gr.Textbox(label="Output")
|
48 |
+
fine_tune_button.click(fine_tune, inputs=[instance_prompt, image1, image2], outputs=output_text)
|
49 |
|
50 |
with gr.Tab("Generate Images"):
|
51 |
with gr.Row():
|
|
|
64 |
demo.launch()
|
65 |
|
66 |
if __name__ == "__main__":
|
67 |
+
gradio_app()
|