Delete apps/old-gradio_app.py
Browse files- apps/old-gradio_app.py +0 -177
apps/old-gradio_app.py
DELETED
|
@@ -1,177 +0,0 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import sys
|
| 3 |
-
import subprocess
|
| 4 |
-
import gradio as gr
|
| 5 |
-
import torch
|
| 6 |
-
import random
|
| 7 |
-
|
| 8 |
-
# Add the project root directory to the Python path
|
| 9 |
-
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
| 10 |
-
|
| 11 |
-
from src.controlnet_image_generator.infer import infer
|
| 12 |
-
|
| 13 |
-
def run_setup_script():
|
| 14 |
-
setup_script = os.path.join(os.path.dirname(__file__), "gradio_app", "setup_scripts.py")
|
| 15 |
-
try:
|
| 16 |
-
result = subprocess.run(["python", setup_script], capture_output=True, text=True, check=True)
|
| 17 |
-
return result.stdout
|
| 18 |
-
except subprocess.CalledProcessError as e:
|
| 19 |
-
print(f"Setup script failed with error: {e.stderr}")
|
| 20 |
-
return f"Setup script failed: {e.stderr}"
|
| 21 |
-
|
| 22 |
-
def run_inference(
|
| 23 |
-
input_image,
|
| 24 |
-
prompt,
|
| 25 |
-
negative_prompt,
|
| 26 |
-
num_steps,
|
| 27 |
-
seed,
|
| 28 |
-
width,
|
| 29 |
-
height,
|
| 30 |
-
guidance_scale,
|
| 31 |
-
controlnet_conditioning_scale,
|
| 32 |
-
use_random_seed=False,
|
| 33 |
-
):
|
| 34 |
-
config_path = "configs/model_ckpts.yaml"
|
| 35 |
-
|
| 36 |
-
if use_random_seed:
|
| 37 |
-
seed = random.randint(0, 2 ** 32)
|
| 38 |
-
|
| 39 |
-
try:
|
| 40 |
-
result = infer(
|
| 41 |
-
config_path=config_path,
|
| 42 |
-
input_image=input_image,
|
| 43 |
-
image_url=None,
|
| 44 |
-
prompt=prompt,
|
| 45 |
-
negative_prompt=negative_prompt,
|
| 46 |
-
num_steps=num_steps,
|
| 47 |
-
seed=seed,
|
| 48 |
-
width=width,
|
| 49 |
-
height=height,
|
| 50 |
-
guidance_scale=guidance_scale,
|
| 51 |
-
controlnet_conditioning_scale=float(controlnet_conditioning_scale),
|
| 52 |
-
)
|
| 53 |
-
result = list(result)[0]
|
| 54 |
-
return result, "Inference completed successfully"
|
| 55 |
-
except Exception as e:
|
| 56 |
-
return [], f"Error during inference: {str(e)}"
|
| 57 |
-
|
| 58 |
-
def stop_app():
|
| 59 |
-
"""Function to stop the Gradio app."""
|
| 60 |
-
try:
|
| 61 |
-
gr.Interface.close_all() # Attempt to close all running Gradio interfaces
|
| 62 |
-
return "Application stopped successfully."
|
| 63 |
-
except Exception as e:
|
| 64 |
-
return f"Error stopping application: {str(e)}"
|
| 65 |
-
|
| 66 |
-
def create_gui():
|
| 67 |
-
cuscustom_css = open("apps/gradio_app/static/style.css").read()
|
| 68 |
-
with gr.Blocks(css=cuscustom_css) as demo:
|
| 69 |
-
gr.Markdown("# ControlNet Image Generation with Pose Detection")
|
| 70 |
-
|
| 71 |
-
with gr.Row():
|
| 72 |
-
with gr.Column():
|
| 73 |
-
input_image = gr.Image(type="filepath", label="Input Image")
|
| 74 |
-
prompt = gr.Textbox(
|
| 75 |
-
label="Prompt",
|
| 76 |
-
value="a man is doing yoga"
|
| 77 |
-
)
|
| 78 |
-
negative_prompt = gr.Textbox(
|
| 79 |
-
label="Negative Prompt",
|
| 80 |
-
value="monochrome, lowres, bad anatomy, worst quality, low quality"
|
| 81 |
-
)
|
| 82 |
-
|
| 83 |
-
with gr.Row():
|
| 84 |
-
width = gr.Slider(
|
| 85 |
-
minimum=256,
|
| 86 |
-
maximum=1024,
|
| 87 |
-
value=512,
|
| 88 |
-
step=64,
|
| 89 |
-
label="Width"
|
| 90 |
-
)
|
| 91 |
-
height = gr.Slider(
|
| 92 |
-
minimum=256,
|
| 93 |
-
maximum=1024,
|
| 94 |
-
value=512,
|
| 95 |
-
step=64,
|
| 96 |
-
label="Height"
|
| 97 |
-
)
|
| 98 |
-
|
| 99 |
-
with gr.Accordion("Advanced Settings", open=False):
|
| 100 |
-
num_steps = gr.Slider(
|
| 101 |
-
minimum=1,
|
| 102 |
-
maximum=100,
|
| 103 |
-
value=30,
|
| 104 |
-
step=1,
|
| 105 |
-
label="Number of Inference Steps"
|
| 106 |
-
)
|
| 107 |
-
use_random_seed = gr.Checkbox(label="Use Random Seed", value=False)
|
| 108 |
-
seed = gr.Slider(
|
| 109 |
-
minimum=0,
|
| 110 |
-
maximum=2**32,
|
| 111 |
-
value=42,
|
| 112 |
-
step=1,
|
| 113 |
-
label="Random Seed",
|
| 114 |
-
visible=True
|
| 115 |
-
)
|
| 116 |
-
|
| 117 |
-
guidance_scale = gr.Slider(
|
| 118 |
-
minimum=1.0,
|
| 119 |
-
maximum=20.0,
|
| 120 |
-
value=7.5,
|
| 121 |
-
step=0.1,
|
| 122 |
-
label="Guidance Scale"
|
| 123 |
-
)
|
| 124 |
-
controlnet_conditioning_scale = gr.Slider(
|
| 125 |
-
minimum=0.0,
|
| 126 |
-
maximum=1.0,
|
| 127 |
-
value=1.0,
|
| 128 |
-
step=0.1,
|
| 129 |
-
label="ControlNet Conditioning Scale"
|
| 130 |
-
)
|
| 131 |
-
|
| 132 |
-
with gr.Column():
|
| 133 |
-
output_images = gr.Image(label="Generated Images")
|
| 134 |
-
output_message = gr.Textbox(label="Status")
|
| 135 |
-
|
| 136 |
-
# with gr.Row():
|
| 137 |
-
submit_button = gr.Button("Generate Images", elem_classes="submit-btn")
|
| 138 |
-
stop_button = gr.Button("Stop Application", elem_classes="stop-btn")
|
| 139 |
-
|
| 140 |
-
def update_seed_visibility(use_random):
|
| 141 |
-
return gr.update(visible=not use_random)
|
| 142 |
-
|
| 143 |
-
use_random_seed.change(
|
| 144 |
-
fn=update_seed_visibility,
|
| 145 |
-
inputs=use_random_seed,
|
| 146 |
-
outputs=seed
|
| 147 |
-
)
|
| 148 |
-
|
| 149 |
-
submit_button.click(
|
| 150 |
-
fn=run_inference,
|
| 151 |
-
inputs=[
|
| 152 |
-
input_image,
|
| 153 |
-
prompt,
|
| 154 |
-
negative_prompt,
|
| 155 |
-
num_steps,
|
| 156 |
-
seed,
|
| 157 |
-
width,
|
| 158 |
-
height,
|
| 159 |
-
guidance_scale,
|
| 160 |
-
controlnet_conditioning_scale,
|
| 161 |
-
use_random_seed,
|
| 162 |
-
],
|
| 163 |
-
outputs=[output_images, output_message]
|
| 164 |
-
)
|
| 165 |
-
|
| 166 |
-
stop_button.click(
|
| 167 |
-
fn=stop_app,
|
| 168 |
-
inputs=[],
|
| 169 |
-
outputs=[output_message]
|
| 170 |
-
)
|
| 171 |
-
|
| 172 |
-
return demo
|
| 173 |
-
|
| 174 |
-
if __name__ == "__main__":
|
| 175 |
-
run_setup_script()
|
| 176 |
-
demo = create_gui()
|
| 177 |
-
demo.launch(share=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|