Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,46 @@
|
|
| 1 |
-
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# app.py
|
| 2 |
|
| 3 |
+
import os
|
| 4 |
+
import gradio as gr
|
| 5 |
+
from huggingface_hub import HfFolder
|
| 6 |
+
|
| 7 |
+
def launch_gradio_app(fine_tune_model, load_model, generate_images, push_to_huggingface, repo_name):
|
| 8 |
+
with gr.Blocks() as demo:
|
| 9 |
+
gr.Markdown("# Dreambooth App")
|
| 10 |
+
|
| 11 |
+
with gr.Tab("Fine-tune Model"):
|
| 12 |
+
with gr.Row():
|
| 13 |
+
instance_images = gr.File(label="Instance Images", file_count="multiple")
|
| 14 |
+
class_images = gr.File(label="Class Images", file_count="multiple")
|
| 15 |
+
with gr.Row():
|
| 16 |
+
instance_prompt = gr.Textbox(label="Instance Prompt")
|
| 17 |
+
class_prompt = gr.Textbox(label="Class Prompt")
|
| 18 |
+
with gr.Row():
|
| 19 |
+
num_train_steps = gr.Number(label="Number of Training Steps", value=800)
|
| 20 |
+
fine_tune_button = gr.Button("Fine-tune Model")
|
| 21 |
+
|
| 22 |
+
with gr.Tab("Generate Images"):
|
| 23 |
+
with gr.Row():
|
| 24 |
+
prompt = gr.Textbox(label="Prompt")
|
| 25 |
+
negative_prompt = gr.Textbox(label="Negative Prompt")
|
| 26 |
+
with gr.Row():
|
| 27 |
+
num_samples = gr.Number(label="Number of Samples", value=1)
|
| 28 |
+
guidance_scale = gr.Number(label="Guidance Scale", value=7.5)
|
| 29 |
+
with gr.Row():
|
| 30 |
+
height = gr.Number(label="Height", value=512)
|
| 31 |
+
width = gr.Number(label="Width", value=512)
|
| 32 |
+
num_inference_steps = gr.Slider(label="Number of Inference Steps", value=50, minimum=1, maximum=100)
|
| 33 |
+
generate_button = gr.Button("Generate Images")
|
| 34 |
+
output_images = gr.Gallery()
|
| 35 |
+
|
| 36 |
+
with gr.Tab("Push to Hugging Face"):
|
| 37 |
+
push_button = gr.Button("Push Model to Hugging Face")
|
| 38 |
+
huggingface_link = gr.Textbox(label="Hugging Face Model Link")
|
| 39 |
+
|
| 40 |
+
fine_tune_button.click(fine_tune_model, inputs=[instance_images, class_images, instance_prompt, class_prompt, num_train_steps], outputs=huggingface_link)
|
| 41 |
+
|
| 42 |
+
generate_button.click(generate_images, inputs=[prompt, negative_prompt, num_samples, height, width, num_inference_steps, guidance_scale], outputs=output_images)
|
| 43 |
+
|
| 44 |
+
push_button.click(push_to_huggingface, inputs=[HfFolder.path, repo_name], outputs=huggingface_link)
|
| 45 |
+
|
| 46 |
+
demo.launch()
|