gengs commited on
Commit
7a759d0
1 Parent(s): ea6c275

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -50
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
- # 获取Hugging Face Token
8
- hf_token = os.environ.get("HF_TOKEN")
9
- login(token=hf_token)
10
 
11
- # 加载模型并配置
12
- pipe = StableDiffusion3Pipeline.from_pretrained("stabilityai/stable-diffusion-3.5-large", torch_dtype=torch.bfloat16)
13
- pipe.load_lora_weights("prithivMLmods/SD3.5-Large-Photorealistic-LoRA", weight_name="Photorealistic-SD3.5-Large-LoRA.safetensors")
14
- pipe.fuse_lora(lora_scale=1.0)
 
15
 
16
- # 如果有GPU,转移到GPU
17
- # pipe.to("cuda")
 
18
 
19
- # 定义图像生成函数,添加种子参数
20
- def generate_image(prompt, seed):
21
- # 设置种子
22
- generator = torch.manual_seed(seed)
 
 
 
 
 
 
 
 
23
 
24
- # 使用模型生成图像
25
- result = pipe(prompt=prompt,
26
- num_inference_steps=24,
27
- guidance_scale=4.0,
28
- width=960, height=1280,
29
- generator=generator)
30
 
31
- # 确保返回 PIL 图像
32
- image = result.images[0]
33
- print(type(image))
34
- return image
35
 
36
- # 创建Gradio界面(使用 Interface)
37
- def gradio_interface():
38
- with gr.Interface(fn=generate_image,
39
- inputs=[gr.Textbox(label="Prompt", value="Man in the style of dark beige and brown, uhd image, youthful protagonists, nonrepresentational photography"),
40
- gr.Slider(minimum=0, maximum=100000, step=1, label="Seed", value=42)],
41
- outputs=gr.Image(type="pil", label="Generated Image")) as demo:
42
- demo.launch()
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()