Update app.py
Browse files
app.py
CHANGED
@@ -1,65 +1,69 @@
|
|
1 |
import gradio as gr
|
2 |
-
import torch
|
3 |
-
from diffusers import StableDiffusion3Pipeline
|
4 |
-
import os
|
5 |
-
from huggingface_hub import login
|
6 |
|
7 |
-
|
8 |
-
hf_token = os.environ.get("HF_TOKEN")
|
9 |
-
login(token=hf_token)
|
10 |
|
11 |
-
#
|
12 |
-
|
13 |
-
|
14 |
-
|
|
|
15 |
|
16 |
-
#
|
17 |
-
#
|
|
|
18 |
|
19 |
-
#
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
|
36 |
-
# 创建Gradio界面(使用 Interface)
|
37 |
-
def gradio_interface():
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
|
44 |
-
# 启动Gradio应用
|
45 |
-
gradio_interface()
|
46 |
|
47 |
-
# 创建Gradio界面
|
48 |
-
# with gr.Blocks() as demo:
|
49 |
-
# gr.Markdown("## Stable Diffusion Image Generation with Seed Control")
|
50 |
|
51 |
-
# # 输入框:提示文本
|
52 |
-
# prompt_input = gr.Textbox(label="Prompt", value="Man in the style of dark beige and brown, uhd image, youthful protagonists, nonrepresentational photography")
|
53 |
|
54 |
-
# # 滑块:种子
|
55 |
-
# seed_input = gr.Slider(minimum=0, maximum=100000, step=1, label="Seed", value=42)
|
56 |
|
57 |
-
# # 输出图像
|
58 |
-
# output_image = gr.Image(type="pil", label="Generated Image")
|
59 |
|
60 |
-
# # 按钮触发事件
|
61 |
-
# generate_btn = gr.Button("Generate Image")
|
62 |
-
# generate_btn.click(fn=generate_image, inputs=[prompt_input, seed_input], outputs=output_image)
|
63 |
|
64 |
-
# # 启动Gradio应用
|
65 |
-
# demo.launch()
|
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
2 |
|
3 |
+
gr.load("models/prithivMLmods/SD3.5-Large-Photorealistic-LoRA").launch()
|
|
|
|
|
4 |
|
5 |
+
# import gradio as gr
|
6 |
+
# import torch
|
7 |
+
# from diffusers import StableDiffusion3Pipeline
|
8 |
+
# import os
|
9 |
+
# from huggingface_hub import login
|
10 |
|
11 |
+
# # 获取Hugging Face Token
|
12 |
+
# hf_token = os.environ.get("HF_TOKEN")
|
13 |
+
# login(token=hf_token)
|
14 |
|
15 |
+
# # 加载模型并配置
|
16 |
+
# pipe = StableDiffusion3Pipeline.from_pretrained("stabilityai/stable-diffusion-3.5-large", torch_dtype=torch.bfloat16)
|
17 |
+
# pipe.load_lora_weights("prithivMLmods/SD3.5-Large-Photorealistic-LoRA", weight_name="Photorealistic-SD3.5-Large-LoRA.safetensors")
|
18 |
+
# pipe.fuse_lora(lora_scale=1.0)
|
19 |
+
|
20 |
+
# # 如果有GPU,转移到GPU
|
21 |
+
# # pipe.to("cuda")
|
22 |
+
|
23 |
+
# # 定义图像生成函数,添加种子参数
|
24 |
+
# def generate_image(prompt, seed):
|
25 |
+
# # 设置种子
|
26 |
+
# generator = torch.manual_seed(seed)
|
27 |
|
28 |
+
# # 使用模型生成图像
|
29 |
+
# result = pipe(prompt=prompt,
|
30 |
+
# num_inference_steps=24,
|
31 |
+
# guidance_scale=4.0,
|
32 |
+
# width=960, height=1280,
|
33 |
+
# generator=generator)
|
34 |
|
35 |
+
# # 确保返回 PIL 图像
|
36 |
+
# image = result.images[0]
|
37 |
+
# print(type(image))
|
38 |
+
# return image
|
39 |
|
40 |
+
# # 创建Gradio界面(使用 Interface)
|
41 |
+
# def gradio_interface():
|
42 |
+
# with gr.Interface(fn=generate_image,
|
43 |
+
# inputs=[gr.Textbox(label="Prompt", value="Man in the style of dark beige and brown, uhd image, youthful protagonists, nonrepresentational photography"),
|
44 |
+
# gr.Slider(minimum=0, maximum=100000, step=1, label="Seed", value=42)],
|
45 |
+
# outputs=gr.Image(type="pil", label="Generated Image")) as demo:
|
46 |
+
# demo.launch()
|
47 |
|
48 |
+
# # 启动Gradio应用
|
49 |
+
# gradio_interface()
|
50 |
|
51 |
+
# # 创建Gradio界面
|
52 |
+
# # with gr.Blocks() as demo:
|
53 |
+
# # gr.Markdown("## Stable Diffusion Image Generation with Seed Control")
|
54 |
|
55 |
+
# # # 输入框:提示文本
|
56 |
+
# # prompt_input = gr.Textbox(label="Prompt", value="Man in the style of dark beige and brown, uhd image, youthful protagonists, nonrepresentational photography")
|
57 |
|
58 |
+
# # # 滑块:种子
|
59 |
+
# # seed_input = gr.Slider(minimum=0, maximum=100000, step=1, label="Seed", value=42)
|
60 |
|
61 |
+
# # # 输出图像
|
62 |
+
# # output_image = gr.Image(type="pil", label="Generated Image")
|
63 |
|
64 |
+
# # # 按钮触发事件
|
65 |
+
# # generate_btn = gr.Button("Generate Image")
|
66 |
+
# # generate_btn.click(fn=generate_image, inputs=[prompt_input, seed_input], outputs=output_image)
|
67 |
|
68 |
+
# # # 启动Gradio应用
|
69 |
+
# # demo.launch()
|