Migrate from yapf to black
Browse filesFiles changed (7)
- .pre-commit-config.yaml+26-12
- .vscode/settings.json+11-8
- app.py+10-8
- app_image_to_3d.py+36-28
- app_text_to_3d.py+49-38
- model.py+25-34
- settings.py+1-1
1234561 unmodified line89101112131415161718192021222324252627282930313233343536repos:- repo: https://github.com/pre-commit/pre-commit-hooksrev: v4.2.0hooks:- id: check-executables-have-shebangs- id: check-json1 unmodified line- id: check-shebang-scripts-are-executable- id: check-toml- id: check-yaml- id: double-quote-string-fixer- id: end-of-file-fixer- id: mixed-line-endingargs: ['--fix=lf']- id: requirements-txt-fixer- id: trailing-whitespace- repo: https://github.com/myint/docformatterrev: v1.4hooks:- id: docformatterargs: ['--in-place']- repo: https://github.com/pycqa/isortrev: 5.12.0hooks:- id: isort- repo: https://github.com/pre-commit/mirrors-mypyrev: v0.991hooks:- id: mypyargs: ['--ignore-missing-imports']additional_dependencies: ['types-python-slugify']- repo: https://github.com/google/yapfrev: v0.32.0hooks:- id: yapfargs: ['--parallel', '--in-place']1234561 unmodified line891011121314151617181920212223242526272829303132333435363738394041424344454647484950repos:- repo: https://github.com/pre-commit/pre-commit-hooksrev: v4.4.0hooks:- id: check-executables-have-shebangs- id: check-json1 unmodified line- id: check-shebang-scripts-are-executable- id: check-toml- id: check-yaml- id: end-of-file-fixer- id: mixed-line-endingargs: ["--fix=lf"]- id: requirements-txt-fixer- id: trailing-whitespace- repo: https://github.com/myint/docformatterrev: v1.7.5hooks:- id: docformatterargs: ["--in-place"]- repo: https://github.com/pycqa/isortrev: 5.12.0hooks:- id: isortargs: ["--profile", "black"]- repo: https://github.com/pre-commit/mirrors-mypyrev: v1.5.1hooks:- id: mypyargs: ["--ignore-missing-imports"]additional_dependencies: ["types-python-slugify", "types-requests", "types-PyYAML"]- repo: https://github.com/psf/blackrev: 23.7.0hooks:- id: blacklanguage_version: python3.10args: ["--line-length", "119"]- repo: https://github.com/kynan/nbstripoutrev: 0.6.1hooks:- id: nbstripoutargs: ["--extra-keys", "metadata.interpreter metadata.kernelspec cell.metadata.pycharm"]- repo: https://github.com/nbQA-dev/nbQArev: 1.7.0hooks:- id: nbqa-black- id: nbqa-pyupgradeargs: ["--py37-plus"]- id: nbqa-isortargs: ["--float-to-top"]
123456789101112131415161718{"python.linting.enabled": true,"python.linting.flake8Enabled": true,"python.linting.pylintEnabled": false,"python.linting.lintOnSave": true,"python.formatting.provider": "yapf","python.formatting.yapfArgs": ["--style={based_on_style: pep8, indent_width: 4, blank_line_before_nested_class_or_def: false, spaces_before_comment: 2, split_before_logical_operator: true}"],"[python]": {"editor.formatOnType": true,"editor.codeActionsOnSave": {"source.organizeImports": true}},"editor.formatOnSave": true,"files.insertFinalNewline": true}123456789101112131415161718192021{"[python]": {"editor.defaultFormatter": "ms-python.black-formatter","editor.formatOnType": true,"editor.codeActionsOnSave": {"source.organizeImports": true}},"black-formatter.args": ["--line-length=119"],"isort.args": ["--profile", "black"],"flake8.args": ["--max-line-length=119"],"ruff.args": ["--line-length=119"],"editor.formatOnSave": true,"files.insertFinalNewline": true}
8 unmodified lines910111213141516171819202122232425262728298 unmodified linesfrom app_text_to_3d import create_demo as create_demo_text_to_3dfrom model import ModelDESCRIPTION = '# [Shap-E](https://github.com/openai/shap-e)'if not torch.cuda.is_available():DESCRIPTION += '\n<p>Running on CPU 🥶 This demo does not work on CPU.</p>'model = Model()with gr.Blocks(css='style.css') as demo:gr.Markdown(DESCRIPTION)gr.DuplicateButton(value='Duplicate Space for private use',elem_id='duplicate-button',visible=os.getenv('SHOW_DUPLICATE_BUTTON') == '1')with gr.Tabs():with gr.Tab(label='Text to 3D'):create_demo_text_to_3d(model)with gr.Tab(label='Image to 3D'):create_demo_image_to_3d(model)demo.queue(max_size=10).launch()8 unmodified lines9101112131415161718192021222324252627282930318 unmodified linesfrom app_text_to_3d import create_demo as create_demo_text_to_3dfrom model import ModelDESCRIPTION = "# [Shap-E](https://github.com/openai/shap-e)"if not torch.cuda.is_available():DESCRIPTION += "\n<p>Running on CPU 🥶 This demo does not work on CPU.</p>"model = Model()with gr.Blocks(css="style.css") as demo:gr.Markdown(DESCRIPTION)gr.DuplicateButton(value="Duplicate Space for private use",elem_id="duplicate-button",visible=os.getenv("SHOW_DUPLICATE_BUTTON") == "1",)with gr.Tabs():with gr.Tab(label="Text to 3D"):create_demo_text_to_3d(model)with gr.Tab(label="Image to 3D"):create_demo_image_to_3d(model)demo.queue(max_size=10).launch()
11 unmodified lines121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556577 unmodified lines6566676869707172737411 unmodified linesdef create_demo(model: Model) -> gr.Blocks:if not pathlib.Path('corgi.png').exists():subprocess.run(shlex.split('wget https://raw.githubusercontent.com/openai/shap-e/d99cedaea18e0989e340163dbaeb4b109fa9e8ec/shap_e/examples/example_data/corgi.png -O corgi.png'))examples = ['corgi.png']def process_example_fn(image_path: str) -> str:return model.run_image(image_path)with gr.Blocks() as demo:with gr.Box():image = gr.Image(label='Input image', show_label=False, type='pil')run_button = gr.Button('Run')result = gr.Model3D(label='Result', show_label=False)with gr.Accordion('Advanced options', open=False):seed = gr.Slider(label='Seed',minimum=0,maximum=MAX_SEED,step=1,value=0)randomize_seed = gr.Checkbox(label='Randomize seed',value=True)guidance_scale = gr.Slider(label='Guidance scale',minimum=1,maximum=20,step=0.1,value=3.0)num_inference_steps = gr.Slider(label='Number of inference steps',minimum=1,maximum=100,step=1,value=64)gr.Examples(examples=examples,inputs=image,outputs=result,fn=process_example_fn,cache_examples=CACHE_EXAMPLES)inputs = [image,7 unmodified linesinputs=[seed, randomize_seed],outputs=seed,queue=False,).then(fn=model.run_image,inputs=inputs,outputs=result,api_name='image-to-3d',)return demo11 unmodified lines12131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263647 unmodified lines727374757677787980818211 unmodified linesdef create_demo(model: Model) -> gr.Blocks:if not pathlib.Path("corgi.png").exists():subprocess.run(shlex.split("wget https://raw.githubusercontent.com/openai/shap-e/d99cedaea18e0989e340163dbaeb4b109fa9e8ec/shap_e/examples/example_data/corgi.png -O corgi.png"))examples = ["corgi.png"]def process_example_fn(image_path: str) -> str:return model.run_image(image_path)with gr.Blocks() as demo:with gr.Box():image = gr.Image(label="Input image", show_label=False, type="pil")run_button = gr.Button("Run")result = gr.Model3D(label="Result", show_label=False)with gr.Accordion("Advanced options", open=False):seed = gr.Slider(label="Seed",minimum=0,maximum=MAX_SEED,step=1,value=0,)randomize_seed = gr.Checkbox(label="Randomize seed", value=True)guidance_scale = gr.Slider(label="Guidance scale",minimum=1,maximum=20,step=0.1,value=3.0,)num_inference_steps = gr.Slider(label="Number of inference steps",minimum=1,maximum=100,step=1,value=64,)gr.Examples(examples=examples,inputs=image,outputs=result,fn=process_example_fn,cache_examples=CACHE_EXAMPLES,)inputs = [image,7 unmodified linesinputs=[seed, randomize_seed],outputs=seed,queue=False,api_name=False,).then(fn=model.run_image,inputs=inputs,outputs=result,api_name="image-to-3d",)return demo
8 unmodified lines910111213141516171819202122231 unmodified line2526272829303132333435363738394041424344454647484950515253545556575859606162636 unmodified lines70717273747576777879808182838485868788898 unmodified linesdef create_demo(model: Model) -> gr.Blocks:examples = ['A chair that looks like an avocado','An airplane that looks like a banana','A spaceship','A birthday cupcake','A chair that looks like a tree','A green boot','A penguin','Ube ice cream cone','A bowl of vegetables',]def process_example_fn(prompt: str) -> str:1 unmodified linewith gr.Blocks() as demo:with gr.Box():with gr.Row(elem_id='prompt-container'):prompt = gr.Text(label='Prompt',show_label=False,max_lines=1,placeholder='Enter your prompt',container=False)run_button = gr.Button('Run', scale=0)result = gr.Model3D(label='Result', show_label=False)with gr.Accordion('Advanced options', open=False):seed = gr.Slider(label='Seed',minimum=0,maximum=MAX_SEED,step=1,value=0)randomize_seed = gr.Checkbox(label='Randomize seed',value=True)guidance_scale = gr.Slider(label='Guidance scale',minimum=1,maximum=20,step=0.1,value=15.0)num_inference_steps = gr.Slider(label='Number of inference steps',minimum=1,maximum=100,step=1,value=64)gr.Examples(examples=examples,inputs=prompt,outputs=result,fn=process_example_fn,cache_examples=CACHE_EXAMPLES)inputs = [prompt,6 unmodified linesinputs=[seed, randomize_seed],outputs=seed,queue=False,).then(fn=model.run_text,inputs=inputs,outputs=result,)run_button.click(fn=randomize_seed_fn,inputs=[seed, randomize_seed],outputs=seed,queue=False,).then(fn=model.run_text,inputs=inputs,outputs=result,api_name='text-to-3d',)return demo8 unmodified lines910111213141516171819202122231 unmodified line25262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970716 unmodified lines787980818283848586878889909192939495969798991008 unmodified linesdef create_demo(model: Model) -> gr.Blocks:examples = ["A chair that looks like an avocado","An airplane that looks like a banana","A spaceship","A birthday cupcake","A chair that looks like a tree","A green boot","A penguin","Ube ice cream cone","A bowl of vegetables",]def process_example_fn(prompt: str) -> str:1 unmodified linewith gr.Blocks() as demo:with gr.Box():with gr.Row(elem_id="prompt-container"):prompt = gr.Text(label="Prompt",show_label=False,max_lines=1,placeholder="Enter your prompt",container=False,)run_button = gr.Button("Run", scale=0)result = gr.Model3D(label="Result", show_label=False)with gr.Accordion("Advanced options", open=False):seed = gr.Slider(label="Seed",minimum=0,maximum=MAX_SEED,step=1,value=0,)randomize_seed = gr.Checkbox(label="Randomize seed", value=True)guidance_scale = gr.Slider(label="Guidance scale",minimum=1,maximum=20,step=0.1,value=15.0,)num_inference_steps = gr.Slider(label="Number of inference steps",minimum=1,maximum=100,step=1,value=64,)gr.Examples(examples=examples,inputs=prompt,outputs=result,fn=process_example_fn,cache_examples=CACHE_EXAMPLES,)inputs = [prompt,6 unmodified linesinputs=[seed, randomize_seed],outputs=seed,queue=False,api_name=False,).then(fn=model.run_text,inputs=inputs,outputs=result,api_name=False,)run_button.click(fn=randomize_seed_fn,inputs=[seed, randomize_seed],outputs=seed,queue=False,api_name=False,).then(fn=model.run_text,inputs=inputs,outputs=result,api_name="text-to-3d",)return demo
9 unmodified lines10111213141516171819202122232 unmodified lines262728293031323334353637383940414243444546474849505152535455565758596061626364659 unmodified linesclass Model:def __init__(self):self.device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')self.pipe = ShapEPipeline.from_pretrained('openai/shap-e',torch_dtype=torch.float16)self.pipe.to(self.device)self.pipe_img = ShapEImg2ImgPipeline.from_pretrained('openai/shap-e-img2img', torch_dtype=torch.float16)self.pipe_img.to(self.device)def to_glb(self, ply_path: str) -> str:2 unmodified linesmesh = mesh.apply_transform(rot)rot = trimesh.transformations.rotation_matrix(np.pi, [0, 1, 0])mesh = mesh.apply_transform(rot)mesh_path = tempfile.NamedTemporaryFile(suffix='.glb', delete=False)mesh.export(mesh_path.name, file_type='glb')return mesh_path.namedef run_text(self,prompt: str,seed: int = 0,guidance_scale: float = 15.0,num_steps: int = 64) -> str:generator = torch.Generator(device=self.device).manual_seed(seed)images = self.pipe(prompt,generator=generator,guidance_scale=guidance_scale,num_inference_steps=num_steps,output_type='mesh').imagesply_path = tempfile.NamedTemporaryFile(suffix='.ply',delete=False,mode='w+b')export_to_ply(images[0], ply_path.name)return self.to_glb(ply_path.name)def run_image(self,image: PIL.Image.Image,seed: int = 0,guidance_scale: float = 3.0,num_steps: int = 64) -> str:generator = torch.Generator(device=self.device).manual_seed(seed)images = self.pipe_img(image,generator=generator,guidance_scale=guidance_scale,num_inference_steps=num_steps,output_type='mesh').imagesply_path = tempfile.NamedTemporaryFile(suffix='.ply',delete=False,mode='w+b')export_to_ply(images[0], ply_path.name)return self.to_glb(ply_path.name)9 unmodified lines10111213141516171819202 unmodified lines232425262728293031323334353637383940414243444546474849505152535455569 unmodified linesclass Model:def __init__(self):self.device = torch.device("cuda" if torch.cuda.is_available() else "cpu")self.pipe = ShapEPipeline.from_pretrained("openai/shap-e", torch_dtype=torch.float16)self.pipe.to(self.device)self.pipe_img = ShapEImg2ImgPipeline.from_pretrained("openai/shap-e-img2img", torch_dtype=torch.float16)self.pipe_img.to(self.device)def to_glb(self, ply_path: str) -> str:2 unmodified linesmesh = mesh.apply_transform(rot)rot = trimesh.transformations.rotation_matrix(np.pi, [0, 1, 0])mesh = mesh.apply_transform(rot)mesh_path = tempfile.NamedTemporaryFile(suffix=".glb", delete=False)mesh.export(mesh_path.name, file_type="glb")return mesh_path.namedef run_text(self, prompt: str, seed: int = 0, guidance_scale: float = 15.0, num_steps: int = 64) -> str:generator = torch.Generator(device=self.device).manual_seed(seed)images = self.pipe(prompt,generator=generator,guidance_scale=guidance_scale,num_inference_steps=num_steps,output_type="mesh",).imagesply_path = tempfile.NamedTemporaryFile(suffix=".ply", delete=False, mode="w+b")export_to_ply(images[0], ply_path.name)return self.to_glb(ply_path.name)def run_image(self, image: PIL.Image.Image, seed: int = 0, guidance_scale: float = 3.0, num_steps: int = 64) -> str:generator = torch.Generator(device=self.device).manual_seed(seed)images = self.pipe_img(image,generator=generator,guidance_scale=guidance_scale,num_inference_steps=num_steps,output_type="mesh",).imagesply_path = tempfile.NamedTemporaryFile(suffix=".ply", delete=False, mode="w+b")export_to_ply(images[0], ply_path.name)return self.to_glb(ply_path.name)
1 unmodified line2345671 unmodified lineimport numpy as npCACHE_EXAMPLES = os.getenv('CACHE_EXAMPLES') == '1'MAX_SEED = np.iinfo(np.int32).max1 unmodified line2345671 unmodified lineimport numpy as npCACHE_EXAMPLES = os.getenv("CACHE_EXAMPLES") == "1"MAX_SEED = np.iinfo(np.int32).max
.pre-commit-config.yaml+26-12
.vscode/settings.json+11-8
app.py+10-8
app_image_to_3d.py+36-28
app_text_to_3d.py+49-38
model.py+25-34
settings.py+1-1