Spaces:
Runtime error
Runtime error
main
Browse files30 unmodified lines3132333435363738394041424344454647484950515253545536 unmodified lines929394959697989910010110210310410542 unmodified lines148149150151152153154155156157158159128 unmodified lines28828929029129229329429529613 unmodified lines31031131231331431531630 unmodified lines'BASE_FLUX_CHECKPOINT': "showlab/makeanything",'BASE_FILE': "flux_merge_lora/flux_merge_4f_wood-fp8_e4m3fn.safetensors",'LORA_REPO': "showlab/makeanything",'LORA_FILE': "recraft/recraft_4f_wood_sculpture.safetensors"},'LEGO': {'BASE_FLUX_CHECKPOINT': "showlab/makeanything",'BASE_FILE': "flux_merge_lora/flux_merge_9f_lego-fp8_e4m3fn.safetensors",'LORA_REPO': "showlab/makeanything",'LORA_FILE': "recraft/recraft_9f_lego.safetensors"},'Sketch': {'BASE_FLUX_CHECKPOINT': "showlab/makeanything",'BASE_FILE': "flux_merge_lora/flux_merge_9f_portrait-fp8_e4m3fn.safetensors",'LORA_REPO': "showlab/makeanything",'LORA_FILE': "recraft/recraft_9f_sketch.safetensors"},'Portrait': {'BASE_FLUX_CHECKPOINT': "showlab/makeanything",'BASE_FILE': "flux_merge_lora/flux_merge_9f_sketch-fp8_e4m3fn.safetensors",'LORA_REPO': "showlab/makeanything",'LORA_FILE': "recraft/recraft_9f_portrait.safetensors"}}36 unmodified lineslogger.info("Loading models...")try:_, model = flux_utils.load_flow_model(BASE_FLUX_CHECKPOINT, torch.float8_e4m3fn, "cpu", disable_mmap=False)clip_l = flux_utils.load_clip_l(CLIP_L_PATH, torch.bfloat16, "cpu", disable_mmap=False)clip_l.eval()t5xxl = flux_utils.load_t5xxl(T5XXL_PATH, torch.bfloat16, "cpu", disable_mmap=False)t5xxl.eval()ae = flux_utils.load_ae(AE_PATH, torch.bfloat16, "cpu", disable_mmap=False)# Load LoRA weightsmultiplier = 1.042 unmodified lines# The function to generate image from a prompt and conditional image@spaces.GPU(duration=180)def infer(prompt, sample_image, frame_num, seed=0):global model, clip_l, t5xxl, ae, lora_modelif model is None or lora_model is None or clip_l is None or t5xxl is None or ae is None:logger.error("Models not loaded. Please load the models first.")return Nonelogger.info(f"Started generating image with prompt: {prompt}")lora_model.to("cuda")128 unmodified lines# File upload for imagesample_image = gr.Image(label="Upload a Conditional Image", type="pil")# Frame number selectionframe_num = gr.Radio([4, 9], label="Select Frame Number", value=9)# Seedseed = gr.Slider(0, np.iinfo(np.int32).max, step=1, label="Seed", value=0)13 unmodified linesload_button.click(fn=load_target_model, inputs=[recraft_model], outputs=[status_box])# Run Buttonrun_button.click(fn=infer, inputs=[prompt, sample_image, frame_num, seed], outputs=[result_image])# Launch the Gradio appdemo.launch()30 unmodified lines313233343536373839404142434445464748495051525354555657585936 unmodified lines9697989910010110210310410510610710810911042 unmodified lines153154155156157158159160161162163164165166167128 unmodified lines29629729829930030113 unmodified lines31531631731831932032130 unmodified lines'BASE_FLUX_CHECKPOINT': "showlab/makeanything",'BASE_FILE': "flux_merge_lora/flux_merge_4f_wood-fp8_e4m3fn.safetensors",'LORA_REPO': "showlab/makeanything",'LORA_FILE': "recraft/recraft_4f_wood_sculpture.safetensors","Frame": 4},'LEGO': {'BASE_FLUX_CHECKPOINT': "showlab/makeanything",'BASE_FILE': "flux_merge_lora/flux_merge_9f_lego-fp8_e4m3fn.safetensors",'LORA_REPO': "showlab/makeanything",'LORA_FILE': "recraft/recraft_9f_lego.safetensors","Frame": 9},'Sketch': {'BASE_FLUX_CHECKPOINT': "showlab/makeanything",'BASE_FILE': "flux_merge_lora/flux_merge_9f_portrait-fp8_e4m3fn.safetensors",'LORA_REPO': "showlab/makeanything",'LORA_FILE': "recraft/recraft_9f_sketch.safetensors","Frame": 9},'Portrait': {'BASE_FLUX_CHECKPOINT': "showlab/makeanything",'BASE_FILE': "flux_merge_lora/flux_merge_9f_sketch-fp8_e4m3fn.safetensors",'LORA_REPO': "showlab/makeanything",'LORA_FILE': "recraft/recraft_9f_portrait.safetensors","Frame": 9}}36 unmodified lineslogger.info("Loading models...")try:if model is None is None or clip_l is None or t5xxl is None or ae is None:_, model = flux_utils.load_flow_model(BASE_FLUX_CHECKPOINT, torch.float8_e4m3fn, "cpu", disable_mmap=False)clip_l = flux_utils.load_clip_l(CLIP_L_PATH, torch.bfloat16, "cpu", disable_mmap=False)clip_l.eval()t5xxl = flux_utils.load_t5xxl(T5XXL_PATH, torch.bfloat16, "cpu", disable_mmap=False)t5xxl.eval()ae = flux_utils.load_ae(AE_PATH, torch.bfloat16, "cpu", disable_mmap=False)# Load LoRA weightsmultiplier = 1.042 unmodified lines# The function to generate image from a prompt and conditional image@spaces.GPU(duration=180)def infer(prompt, sample_image, recraft_model, seed=0):global model, clip_l, t5xxl, ae, lora_modelif model is None or lora_model is None or clip_l is None or t5xxl is None or ae is None:logger.error("Models not loaded. Please load the models first.")return Nonemodel_path = model_paths[selected_model]frame_num = model_path['Frame']logger.info(f"Started generating image with prompt: {prompt}")lora_model.to("cuda")128 unmodified lines# File upload for imagesample_image = gr.Image(label="Upload a Conditional Image", type="pil")# Seedseed = gr.Slider(0, np.iinfo(np.int32).max, step=1, label="Seed", value=0)13 unmodified linesload_button.click(fn=load_target_model, inputs=[recraft_model], outputs=[status_box])# Run Buttonrun_button.click(fn=infer, inputs=[prompt, sample_image, recraft_model, seed], outputs=[result_image])# Launch the Gradio appdemo.launch()
gradio_app.py+22-17