Update app.py
Browse files18 unmodified lines192021222324251 unmodified line272829303132333435363738394041424344454647484927 unmodified lines77787980818226 unmodified lines10911011111211311411511637 unmodified lines154155156157158159137 unmodified lines2972982993003013023033 unmodified lines3073083093103113123133143153163173183193203213223233243253263273283293303313323333343356 unmodified lines34234334434534634718 unmodified linesrepo_id="black-forest-labs/FLUX.1-Redux-dev",filename="flux1-redux-dev.safetensors",local_dir="models/style_models",token=HF_TOKEN # ํ ํฐ ์ ๋ฌ)hf_hub_download(repo_id="black-forest-labs/FLUX.1-Depth-dev",1 unmodified linelocal_dir="models/diffusion_models",token=HF_TOKEN)# ๋๋จธ์ง hf_hub_download ํธ์ถ์๋ token=HF_TOKEN ์ถ๊ฐhf_hub_download(repo_id="Comfy-Org/sigclip_vision_384", filename="sigclip_vision_patch14_384.safetensors", local_dir="models/clip_vision", token=HF_TOKEN)hf_hub_download(repo_id="Kijai/DepthAnythingV2-safetensors", filename="depth_anything_v2_vitl_fp32.safetensors", local_dir="models/depthanything", token=HF_TOKEN)hf_hub_download(repo_id="black-forest-labs/FLUX.1-dev", filename="ae.safetensors", local_dir="models/vae/FLUX1", token=HF_TOKEN)hf_hub_download(repo_id="comfyanonymous/flux_text_encoders", filename="clip_l.safetensors", local_dir="models/text_encoders", token=HF_TOKEN)t5_path = hf_hub_download(repo_id="comfyanonymous/flux_text_encoders", filename="t5xxl_fp16.safetensors", local_dir="models/text_encoders/t5", token=HF_TOKEN)# Import all the necessary functions from the original scriptdef get_value_at_index(obj: Union[Sequence, Mapping], index: int) -> Any:try:return obj[index]except KeyError:return obj["result"][index]# Add all the necessary setup functions from the original scriptdef find_path(name: str, path: str = None) -> str:if path is None:path = os.getcwd()27 unmodified linesadd_comfyui_directory_to_sys_path()add_extra_model_paths()def import_custom_nodes() -> None:import asyncioimport execution26 unmodified linesimport_custom_nodes()# Global variables for preloaded models and constants#with torch.inference_mode():# Initialize constantsintconstant = NODE_CLASS_MAPPINGS["INTConstant"]()CONST_1024 = intconstant.get_value(value=1024)37 unmodified linesDEPTH_MODEL = downloadandloaddepthanythingv2model.loadmodel(model="depth_anything_v2_vitl_fp32.safetensors")cliptextencode = CLIPTextEncode()loadimage = LoadImage()vaeencode = VAEEncode()137 unmodified lines)# Save imageprefix = cr_text.text_multiline(text="Flux_BFL_Depth_Redux")saved = saveimage.save_images(filename_prefix=get_value_at_index(prefix, 0),3 unmodified linesreturn saved_path# Create Gradio interfaceexamples = [["", "mona.png", "receita-tacos.webp", 15, 0.6],["a woman looking at a house catching fire on the background", "disaster_girl.png", "abaporu.jpg", 15, 0.15],["istanbul aerial, dramatic photography", "natasha.png", "istambul.jpg", 15, 0.5],]output_image = gr.Image(label="Generated Image")with gr.Blocks() as app:gr.Markdown("# FLUX Style Shaping")gr.Markdown("Flux[dev] Redux + Flux[dev] Depth ComfyUI workflow by [Nathan Shipley](https://x.com/CitizenPlain) running directly on Gradio. [workflow](https://gist.github.com/nathanshipley/7a9ac1901adde76feebe58d558026f68) - [how to convert your any comfy workflow to gradio (soon)](#)")with gr.Row():with gr.Column():prompt_input = gr.Textbox(label="Prompt", placeholder="Enter your prompt here...")with gr.Row():with gr.Group():structure_image = gr.Image(label="Structure Image", type="filepath")depth_strength = gr.Slider(minimum=0, maximum=50, value=15, label="Depth Strength")with gr.Group():style_image = gr.Image(label="Style Image", type="filepath")style_strength = gr.Slider(minimum=0, maximum=1, value=0.5, label="Style Strength")generate_btn = gr.Button("Generate")gr.Examples(examples=examples,6 unmodified lineswith gr.Column():output_image.render()generate_btn.click(fn=generate_image,inputs=[prompt_input, structure_image, style_image, depth_strength, style_strength],18 unmodified lines192021222324251 unmodified line2728293031323334353637383940414243444546474849505152535455565758596061626364656667686927 unmodified lines97989910010110210310426 unmodified lines13113213313413513637 unmodified lines174175176177178179180181137 unmodified lines3193203213223233243253 unmodified lines3293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773786 unmodified lines38538638738838939039139239339439539639739839940040140240340440540618 unmodified linesrepo_id="black-forest-labs/FLUX.1-Redux-dev",filename="flux1-redux-dev.safetensors",local_dir="models/style_models",token=HF_TOKEN)hf_hub_download(repo_id="black-forest-labs/FLUX.1-Depth-dev",1 unmodified linelocal_dir="models/diffusion_models",token=HF_TOKEN)hf_hub_download(repo_id="Comfy-Org/sigclip_vision_384",filename="sigclip_vision_patch14_384.safetensors",local_dir="models/clip_vision",token=HF_TOKEN)hf_hub_download(repo_id="Kijai/DepthAnythingV2-safetensors",filename="depth_anything_v2_vitl_fp32.safetensors",local_dir="models/depthanything",token=HF_TOKEN)hf_hub_download(repo_id="black-forest-labs/FLUX.1-dev",filename="ae.safetensors",local_dir="models/vae/FLUX1",token=HF_TOKEN)hf_hub_download(repo_id="comfyanonymous/flux_text_encoders",filename="clip_l.safetensors",local_dir="models/text_encoders",token=HF_TOKEN)t5_path = hf_hub_download(repo_id="comfyanonymous/flux_text_encoders",filename="t5xxl_fp16.safetensors",local_dir="models/text_encoders/t5",token=HF_TOKEN)def get_value_at_index(obj: Union[Sequence, Mapping], index: int) -> Any:try:return obj[index]except KeyError:return obj["result"][index]def find_path(name: str, path: str = None) -> str:if path is None:path = os.getcwd()27 unmodified linesadd_comfyui_directory_to_sys_path()add_extra_model_paths()def import_custom_nodes() -> None:import asyncioimport execution26 unmodified linesimport_custom_nodes()# Global variables for preloaded models and constantsintconstant = NODE_CLASS_MAPPINGS["INTConstant"]()CONST_1024 = intconstant.get_value(value=1024)37 unmodified linesDEPTH_MODEL = downloadandloaddepthanythingv2model.loadmodel(model="depth_anything_v2_vitl_fp32.safetensors")# Initialize other nodescliptextencode = CLIPTextEncode()loadimage = LoadImage()vaeencode = VAEEncode()137 unmodified lines)# Save imageprefix = cr_text.text_multiline(text="Virtual_TryOn")saved = saveimage.save_images(filename_prefix=get_value_at_index(prefix, 0),3 unmodified linesreturn saved_path# Create Gradio interfaceexamples = [["person wearing fashionable clothing", "person.jpg", "fashion1.jpg", 15, 0.6],["person wearing elegant dress", "model1.jpg", "dress1.jpg", 15, 0.5],["person wearing casual outfit", "person2.jpg", "outfit1.jpg", 15, 0.5],]output_image = gr.Image(label="Virtual Try-On Result")with gr.Blocks() as app:gr.Markdown("# AI Fashion Virtual Try-On")gr.Markdown("Upload your photo and try on different clothing items virtually using AI. The system will generate an image of you wearing the selected clothing while maintaining your pose and appearance.")with gr.Row():with gr.Column():prompt_input = gr.Textbox(label="Style Description",placeholder="Describe the desired style (e.g., 'person wearing elegant dress')")with gr.Row():with gr.Group():structure_image = gr.Image(label="Your Photo",type="filepath",info="Upload a full-body photo of yourself")depth_strength = gr.Slider(minimum=0,maximum=50,value=15,label="Fitting Strength")with gr.Group():style_image = gr.Image(label="Clothing Item",type="filepath",info="Upload the clothing item you want to try on")style_strength = gr.Slider(minimum=0,maximum=1,value=0.5,label="Style Transfer Strength")generate_btn = gr.Button("Generate Try-On")gr.Examples(examples=examples,6 unmodified lineswith gr.Column():output_image.render()gr.Markdown("""### How to Use:1. Upload your full-body photo2. Upload the clothing item you want to try on3. Adjust the fitting and style strength if needed4. Add a description of the desired style (optional)5. Click 'Generate Try-On' to see the result### Tips:- Use clear, well-lit photos- Full-body photos work best- Clothing items should be on a clean background- Adjust the fitting strength for better results""")generate_btn.click(fn=generate_image,inputs=[prompt_input, structure_image, style_image, depth_strength, style_strength],
app.py+86-27