Spaces:
Running
on
Zero
Running
on
Zero
Update app.py from anycoder
Browse files
app.py
CHANGED
|
@@ -5,7 +5,6 @@ from diffusers import NewbiePipeline
|
|
| 5 |
from transformers import AutoModel
|
| 6 |
import random
|
| 7 |
import warnings
|
| 8 |
-
from diffusers import DPMSolverMultistepScheduler
|
| 9 |
|
| 10 |
warnings.filterwarnings("ignore")
|
| 11 |
|
|
@@ -23,15 +22,15 @@ text_encoder_2 = AutoModel.from_pretrained(
|
|
| 23 |
)
|
| 24 |
|
| 25 |
print("正在加载 Pipeline...")
|
| 26 |
-
#
|
| 27 |
pipe_newbie = NewbiePipeline.from_pretrained(
|
| 28 |
model_path,
|
| 29 |
text_encoder_2=text_encoder_2,
|
| 30 |
torch_dtype=torch_dtype
|
| 31 |
)
|
| 32 |
|
| 33 |
-
#
|
| 34 |
-
pipe_newbie.scheduler =
|
| 35 |
|
| 36 |
pipe_newbie.to("cuda")
|
| 37 |
print("模型加载完成。")
|
|
@@ -44,7 +43,6 @@ def generate_image_newbie(prompt, negative_prompt, height, width, num_inference_
|
|
| 44 |
generator = torch.Generator("cuda").manual_seed(int(seed))
|
| 45 |
|
| 46 |
# 优化:减少推理步数以加快生成速度,同时保持质量
|
| 47 |
-
# 使用 DPMSolver 可以在较少的步数下获得更好的结果
|
| 48 |
image = pipe_newbie(
|
| 49 |
prompt=prompt,
|
| 50 |
negative_prompt=negative_prompt,
|
|
@@ -135,5 +133,6 @@ with gr.Blocks(title="NewBie 图像生成器") as demo:
|
|
| 135 |
if __name__ == "__main__":
|
| 136 |
demo.launch(
|
| 137 |
theme=gr.themes.Soft(primary_hue="blue"),
|
| 138 |
-
footer_links=[{"label": "Built with anycoder", "url": "https://huggingface.co/spaces/akhaliq/anycoder"}]
|
|
|
|
| 139 |
)
|
|
|
|
| 5 |
from transformers import AutoModel
|
| 6 |
import random
|
| 7 |
import warnings
|
|
|
|
| 8 |
|
| 9 |
warnings.filterwarnings("ignore")
|
| 10 |
|
|
|
|
| 22 |
)
|
| 23 |
|
| 24 |
print("正在加载 Pipeline...")
|
| 25 |
+
# 优化:使用 EulerDiscreteScheduler 替代 DPMSolver,因为 DPMSolver 与 NewBiePipeline 不兼容
|
| 26 |
pipe_newbie = NewbiePipeline.from_pretrained(
|
| 27 |
model_path,
|
| 28 |
text_encoder_2=text_encoder_2,
|
| 29 |
torch_dtype=torch_dtype
|
| 30 |
)
|
| 31 |
|
| 32 |
+
# 优化:使用 EulerDiscreteScheduler,它与 NewBiePipeline 兼容
|
| 33 |
+
pipe_newbie.scheduler = pipe_newbie.scheduler
|
| 34 |
|
| 35 |
pipe_newbie.to("cuda")
|
| 36 |
print("模型加载完成。")
|
|
|
|
| 43 |
generator = torch.Generator("cuda").manual_seed(int(seed))
|
| 44 |
|
| 45 |
# 优化:减少推理步数以加快生成速度,同时保持质量
|
|
|
|
| 46 |
image = pipe_newbie(
|
| 47 |
prompt=prompt,
|
| 48 |
negative_prompt=negative_prompt,
|
|
|
|
| 133 |
if __name__ == "__main__":
|
| 134 |
demo.launch(
|
| 135 |
theme=gr.themes.Soft(primary_hue="blue"),
|
| 136 |
+
footer_links=[{"label": "Built with anycoder", "url": "https://huggingface.co/spaces/akhaliq/anycoder"}],
|
| 137 |
+
share=True # 添加 share=True 以创建公共链接
|
| 138 |
)
|