Download app.py from laishi/lighting: direct link, hf CLI and curl.
- Browser
- Download file 1.4 kB
-
https://huggingface.co/spaces/laishi/lighting/resolve/main/app.py
- Command line
-
hf download hf://spaces/laishi/lighting/app.py
-
curl -L -o app.py https://huggingface.co/spaces/laishi/lighting/resolve/main/app.py
1.4 kB
| # 安装必要的库 | |
| !pip install -q diffusers transformers accelerate | |
| from diffusers import AutoPipelineForImage2Image, AutoPipelineForText2Image | |
| from diffusers.utils import load_image, make_image_grid | |
| import torch | |
| # 定义文本到图像管道 | |
| pipeline_text2image = AutoPipelineForText2Image.from_pretrained("stabilityai/sdxl-turbo", torch_dtype=torch.float32).to("cpu") | |
| # 使用 from_pipe 避免加载检查点时消耗额外内存 | |
| pipeline_image2image = AutoPipelineForImage2Image.from_pipe(pipeline_text2image).to("cpu") | |
| # 加载原图和线条图(确保这些链接是有效的公共 URL) | |
| init_image = load_image("https://huggingface.co/spaces/laishi/lighting/blob/main/dafang20x526.jpg").resize((720, 526)) | |
| control_image = load_image("https://huggingface.co/spaces/laishi/lighting/blob/main/linearh720x526.png").resize((720, 526)) | |
| # 修改提示词 | |
| prompt = "Night view of commercial buildings with illuminated LED lighting, aerial perspective, vibrant colors, detailed cityscape" | |
| # 生成新图像 | |
| image = pipeline_image2image( | |
| prompt, | |
| image=init_image, | |
| control_image=control_image, # 添加控制图 | |
| strength=0.9, # 增加控制图的影响 | |
| guidance_scale=0.0, | |
| num_inference_steps=10 | |
| ).images[0] | |
| # 创建图像网格 | |
| grid = make_image_grid([init_image, image], rows=1, cols=2) | |
| # 保存图像网格 | |
| grid.save("lighting-grid.png") | |
| image.save("lighting.png") | |