Spaces:
Runtime error
Runtime error
Rename app1.py to app.py
Browse files- app1.py → app.py +46 -48
app1.py → app.py
RENAMED
|
@@ -1,49 +1,47 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
import torch
|
| 3 |
-
from annotator.util import resize_image, HWC3
|
| 4 |
-
from
|
| 5 |
-
from cldm.
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
model =
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
#
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
demo = create_demo(process)
|
| 49 |
demo.launch()
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import torch
|
| 3 |
+
from annotator.util import resize_image, HWC3
|
| 4 |
+
from cldm.model import create_model, load_state_dict
|
| 5 |
+
from cldm.ddim_hacked import DDIMSampler
|
| 6 |
+
|
| 7 |
+
# Initialize the model and other components
|
| 8 |
+
model = create_model('./models/cldm_v21_512_latctrl_coltrans.yaml').cpu()
|
| 9 |
+
model.load_state_dict(load_state_dict('xywwww/scene_diffusion/checkpoints/epoch=25-step=112553.ckpt', location='cuda'), strict=False)
|
| 10 |
+
model = model.cuda()
|
| 11 |
+
ddim_sampler = DDIMSampler(model)
|
| 12 |
+
|
| 13 |
+
def process(input_image, prompt, a_prompt, n_prompt, num_samples, image_resolution, ddim_steps, guess_mode, strength, scale, seed, eta, low_threshold, high_threshold):
|
| 14 |
+
with torch.no_grad():
|
| 15 |
+
img = resize_image(HWC3(input_image), image_resolution)
|
| 16 |
+
H, W, C = img.shape
|
| 17 |
+
# detected_map = apply_canny(img, low_threshold, high_threshold)
|
| 18 |
+
# detected_map = HWC3(detected_map)
|
| 19 |
+
# Add the rest of the processing logic here
|
| 20 |
+
|
| 21 |
+
def create_demo(process):
|
| 22 |
+
with gr.Blocks() as demo:
|
| 23 |
+
with gr.Row():
|
| 24 |
+
with gr.Column():
|
| 25 |
+
input_image = gr.Image()
|
| 26 |
+
prompt = gr.Textbox(label="Prompt", submit_btn=True)
|
| 27 |
+
a_prompt = gr.Textbox(label="Additional Prompt")
|
| 28 |
+
n_prompt = gr.Textbox(label="Negative Prompt")
|
| 29 |
+
with gr.Accordion("Advanced options", open=False):
|
| 30 |
+
num_samples = gr.Slider(label="Number of images", minimum=1, maximum=10, value=1, step=1)
|
| 31 |
+
image_resolution = gr.Slider(label="Image resolution", minimum=256, maximum=1024, value=512, step=256)
|
| 32 |
+
ddim_steps = gr.Slider(label="DDIM Steps", minimum=1, maximum=100, value=50, step=1)
|
| 33 |
+
guess_mode = gr.Checkbox(label="Guess Mode")
|
| 34 |
+
strength = gr.Slider(label="Strength", minimum=0.0, maximum=1.0, value=0.5, step=0.1)
|
| 35 |
+
scale = gr.Slider(label="Scale", minimum=0.1, maximum=30.0, value=10.0, step=0.1)
|
| 36 |
+
seed = gr.Slider(label="Seed", minimum=0, maximum=10000, value=42, step=1)
|
| 37 |
+
eta = gr.Slider(label="ETA", minimum=0.0, maximum=1.0, value=0.0, step=0.1)
|
| 38 |
+
low_threshold = gr.Slider(label="Canny Low Threshold", minimum=1, maximum=255, value=100, step=1)
|
| 39 |
+
high_threshold = gr.Slider(label="Canny High Threshold", minimum=1, maximum=255, value=200, step=1)
|
| 40 |
+
submit = gr.Button("Generate")
|
| 41 |
+
with gr.Column():
|
| 42 |
+
output_image = gr.Image()
|
| 43 |
+
submit.click(fn=process, inputs=[input_image, prompt, a_prompt, n_prompt, num_samples, image_resolution, ddim_steps, guess_mode, strength, scale, seed, eta, low_threshold, high_threshold], outputs=output_image)
|
| 44 |
+
return demo
|
| 45 |
+
|
| 46 |
+
demo = create_demo(process)
|
|
|
|
|
|
|
| 47 |
demo.launch()
|