Spaces:
Configuration error
Configuration error
Update app.py
Browse files32 unmodified lines3334353637383924 unmodified lines6465666768692 unmodified lines72737475767778798081828384858687888990919293949596979856 unmodified lines155156157158159160161113 unmodified lines27527627727827928028133 unmodified lines315316317318319320321155 unmodified lines47747847948048148248348448548648748848949049149249349432 unmodified linesfrom tqdm import tqdmfrom pathlib import Pathimport gradiofrom gradio.utils import get_cache_folderfrom stablenormal.pipeline_yoso_normal import YOSONormalsPipeline24 unmodified lines"Missing image in the first pane: upload a file or use one from the gallery below.")def process_image(pipe,path_input,2 unmodified linesprint(f"Processing image {name_base}{name_ext}")path_output_dir = tempfile.mkdtemp()# path_out_fp32 = os.path.join(path_output_dir, f"{name_base}_normal_fp32.npy")path_out_png = os.path.join(path_output_dir, f"{name_base}_normal_colored.png")input_image = Image.open(path_input)# input_image = center_crop(input_image)pipe_out = pipe(input_image,match_input_resolution=False,return_intermediate_result=False)normal_pred = pipe_out.prediction[0, :, :]normal_colored = pipe.image_processor.visualize_normals(pipe_out.prediction)normal_colored[-1].save(path_out_png)print(path_out_png)# np.save(path_out_fp32, normal_pred)# path_out_vis = os.path.join(path_output_dir, f"{name_base}_normal_refinement_process.gif")# normal_colored[0].save(path_out_vis, save_all=True,# append_images=normal_colored[1:],# duration=400, loop=0)return [input_image, path_out_png]def center_crop(img):56 unmodified linespipe_out = pipe(frame_pil,match_input_resolution=False,return_intermediate_result=False)processed_frame = pipe.image_processor.visualize_normals( # noqa113 unmodified lines]),inputs=[image_input],outputs=[image_output_slider],cache_examples=True,directory_name="examples_image",)33 unmodified linesinputs=[video_input],outputs=[processed_frames, video_output_files],directory_name="examples_video",cache_examples=True,)with gr.Tab("Panorama"):155 unmodified linesos.system("pip freeze")device = torch.device("cuda" if torch.cuda.is_available() else "cpu")x_start_pipeline = YOSONormalsPipeline.from_pretrained('Stable-X/yoso-normal-v0-1', trust_remote_code=True,t_start=300).to(device)dinov2_prior = DINOv2_Encoder(size=672)dinov2_prior.to(device)pipe = StableNormalPipeline.from_pretrained('Stable-X/stable-normal-v0-1', t_start=300, trust_remote_code=True,scheduler=HEURI_DDIMScheduler(prediction_type='sample',beta_start=0.00085, beta_end=0.0120,beta_schedule = "scaled_linear"))# two stage concatpipe.x_start_pipeline = x_start_pipelinepipe.prior = dinov2_priorpipe.to(device)32 unmodified lines3334353637383924 unmodified lines646566676869707172737475767778798081822 unmodified lines85868788899091929394959697989910010110210310456 unmodified lines161162163164165166113 unmodified lines28028128228328428528633 unmodified lines320321322323324325326155 unmodified lines48248348448548648748848949049149249349449549649749832 unmodified linesfrom tqdm import tqdmfrom pathlib import Pathimport cv2import gradiofrom gradio.utils import get_cache_folderfrom stablenormal.pipeline_yoso_normal import YOSONormalsPipeline24 unmodified lines"Missing image in the first pane: upload a file or use one from the gallery below.")def resize_image(input_image, resolution):input_image = np.asarray(input_image)H, W, C = input_image.shapeH = float(H)W = float(W)k = float(resolution) / min(H, W)H *= kW *= kH = int(np.round(H / 64.0)) * 64W = int(np.round(W / 64.0)) * 64img = cv2.resize(input_image, (W, H), interpolation=cv2.INTER_LANCZOS4 if k > 1 else cv2.INTER_AREA)return Image.fromarray(img)def process_image(pipe,path_input,2 unmodified linesprint(f"Processing image {name_base}{name_ext}")path_output_dir = tempfile.mkdtemp()path_out_png = os.path.join(path_output_dir, f"{name_base}_normal_colored.png")input_image = Image.open(path_input)input_image = resize_image(input_image, default_image_processing_resolution)pipe_out = pipe(input_image,match_input_resolution=False,processing_resolution=max(input_image.size))normal_pred = pipe_out.prediction[0, :, :]normal_colored = pipe.image_processor.visualize_normals(pipe_out.prediction)normal_colored[-1].save(path_out_png)return [input_image, path_out_png]def center_crop(img):56 unmodified linespipe_out = pipe(frame_pil,match_input_resolution=False,)processed_frame = pipe.image_processor.visualize_normals( # noqa113 unmodified lines]),inputs=[image_input],outputs=[image_output_slider],cache_examples=False,directory_name="examples_image",)33 unmodified linesinputs=[video_input],outputs=[processed_frames, video_output_files],directory_name="examples_video",cache_examples=False,)with gr.Tab("Panorama"):155 unmodified linesos.system("pip freeze")device = torch.device("cuda" if torch.cuda.is_available() else "cpu")x_start_pipeline = YOSONormalsPipeline.from_pretrained('weights/yoso-normal-v0-1', trust_remote_code=True,t_start=300).to(device)dinov2_prior = DINOv2_Encoder(size=672)dinov2_prior.to(device)pipe = StableNormalPipeline.from_pretrained('weights/stable-normal-v0-1', t_start=300, trust_remote_code=True,scheduler=HEURI_DDIMScheduler(prediction_type='sample',beta_start=0.00085, beta_end=0.0120,beta_schedule = "scaled_linear"))pipe.x_start_pipeline = x_start_pipelinepipe.prior = dinov2_priorpipe.to(device)
app.py+22-18