Vignesh455 commited on
Commit
c0aebfb
1 Parent(s): a384a0a

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +149 -0
  2. header.html +13 -0
  3. requirements.txt +12 -0
app.py ADDED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from PIL import Image
3
+ import diffusers
4
+ from diffusers.models import AutoencoderKL
5
+
6
+ vae = AutoencoderKL.from_pretrained("stabilityai/sd-vae-ft-mse")
7
+
8
+
9
+ def read_content(file_path: str) -> str:
10
+ """read the content of target file
11
+ """
12
+ with open(file_path, 'r', encoding='utf-8') as f:
13
+ content = f.read()
14
+
15
+ return content
16
+
17
+
18
+ def predict(prompt, negative_prompt, guidance_scale, num_inference_steps,model, scheduler, lora, lora_weight):
19
+ pipeline = diffusers.DiffusionPipeline.from_pretrained("SG161222/Realistic_Vision_V6.0_B1_noVAE", vae=vae).to("cuda")
20
+ pipeline.safety_checker = lambda images, **kwargs: (images, [False] * len(images))
21
+ if model == "Realistic_V5.1":
22
+ pipeline = diffusers.DiffusionPipeline.from_pretrained("SG161222/Realistic_Vision_V5.1_noVAE", vae=vae).to("cuda")
23
+ if model == "Realistic_V5.0":
24
+ pipeline = diffusers.DiffusionPipeline.from_pretrained("SG161222/Realistic_Vision_V5.0_noVAE", vae=vae).to("cuda")
25
+ if model == "EpicRealism":
26
+ pipeline = diffusers.DiffusionPipeline.from_pretrained("emilianJR/epiCRealism", vae=vae).to("cuda")
27
+ pipeline.safety_checker = lambda images, **kwargs: (images, [False] * len(images))
28
+
29
+ scheduler_class_name = scheduler.split("-")[0]
30
+ add_kwargs = {}
31
+ if len(scheduler.split("-")) > 1:
32
+ add_kwargs["use_karras_sigmas"] = True
33
+ if len(scheduler.split("-")) > 2:
34
+ add_kwargs["algorithm_type"] = "sde-dpmsolver++"
35
+ scheduler = getattr(diffusers, scheduler_class_name)
36
+
37
+ pipeline.scheduler = scheduler.from_pretrained("emilianJR/epiCRealism", subfolder="scheduler", **add_kwargs)
38
+
39
+
40
+ if lora == "nayanthara":
41
+ lora = "profaker/Naya_lora"
42
+ if lora == "saipallavi":
43
+ lora = "profaker/saipallavi_lora"
44
+ if lora == "shobita":
45
+ lora = "profaker/Shobita_lora"
46
+ if lora == "surya":
47
+ lora = "profaker/Surya_lora"
48
+ if lora == "vijay":
49
+ lora = "profaker/Vijay_lora"
50
+ if lora == "None":
51
+ images = pipeline(
52
+ prompt=prompt,
53
+ negative_prompt=negative_prompt,
54
+ num_inference_steps=int(num_inference_steps),
55
+ guidance_scale=guidance_scale,
56
+ clip_skip=1
57
+ ).images[0]
58
+ print("Prompt", prompt)
59
+ print("Negative", negative_prompt)
60
+ print("Steps", num_inference_steps)
61
+ print("Scale", guidance_scale)
62
+ print("Scheduler", scheduler)
63
+ return images
64
+
65
+ pipeline.load_lora_weights(lora)
66
+
67
+ images = pipeline(
68
+ prompt=prompt,
69
+ negative_prompt=negative_prompt,
70
+ num_inference_steps=int(num_inference_steps),
71
+ guidance_scale=guidance_scale,
72
+ cross_attention_kwargs={"scale": lora_weight}
73
+ ).images[0]
74
+
75
+ print("Prompt", prompt)
76
+ print("Negative", negative_prompt)
77
+ print("Steps", num_inference_steps)
78
+ print("Scale", guidance_scale)
79
+ print("Scheduler", scheduler)
80
+
81
+ return images
82
+
83
+
84
+ css = '''
85
+ .gradio-container{max-width: 1100px !important}
86
+ #image_upload{min-height:400px}
87
+ #image_upload [data-testid="image"], #image_upload [data-testid="image"] > div{min-height: 400px}
88
+ #mask_radio .gr-form{background:transparent; border: none}
89
+ #word_mask{margin-top: .75em !important}
90
+ #word_mask textarea:disabled{opacity: 0.3}
91
+ .footer {margin-bottom: 45px;margin-top: 35px;text-align: center;border-bottom: 1px solid #e5e5e5}
92
+ .footer>p {font-size: .8rem; display: inline-block; padding: 0 10px;transform: translateY(10px);background: white}
93
+ .dark .footer {border-color: #303030}
94
+ .dark .footer>p {background: #0b0f19}
95
+ .acknowledgments h4{margin: 1.25em 0 .25em 0;font-weight: bold;font-size: 115%}
96
+ #image_upload .touch-none{display: flex}
97
+ @keyframes spin {
98
+ from {
99
+ transform: rotate(0deg);
100
+ }
101
+ to {
102
+ transform: rotate(360deg);
103
+ }
104
+ }
105
+
106
+ #prompt-container{margin-top:-18px;}
107
+ #prompt-container .form{border-top-left-radius: 0;border-top-right-radius: 0}
108
+ '''
109
+
110
+ image_blocks = gr.Blocks(css=css, elem_id="total-container")
111
+ with image_blocks as demo:
112
+ gr.HTML(read_content("header.html"))
113
+ with gr.Row():
114
+ with gr.Column():
115
+ with gr.Row(elem_id="prompt-container", equal_height=True):
116
+ with gr.Row():
117
+ prompt = gr.Textbox(placeholder="Your prompt", show_label=False, elem_id="prompt", lines=5)
118
+
119
+ with gr.Accordion(label="Advanced Settings", open=False):
120
+ with gr.Row(equal_height=True):
121
+ guidance_scale = gr.Number(value=7.5, minimum=1.0, maximum=20.0, step=0.1, label="guidance_scale")
122
+ steps = gr.Number(value=40, minimum=0, maximum=100, step=1, label="steps")
123
+ with gr.Row(equal_height=True):
124
+ negative_prompt = gr.Textbox(label="negative_prompt", placeholder="Your negative prompt",
125
+ info="what you don't want to see in the image")
126
+ with gr.Row(equal_height=True):
127
+ models = ['Realistic_V6.0','Realistic_V5.1','Realistic_V5.0','EpicRealism']
128
+ model = gr.Dropdown(label="Models",choices=models,value="Realistic_V6.0")
129
+ with gr.Row(equal_height=True):
130
+ schedulers = ["DEISMultistepScheduler", "HeunDiscreteScheduler", "EulerDiscreteScheduler",
131
+ "DPMSolverMultistepScheduler", "DPMSolverMultistepScheduler-Karras",
132
+ "DPMSolverMultistepScheduler-Karras-SDE"]
133
+ scheduler = gr.Dropdown(label="Schedulers", choices=schedulers,
134
+ value="DPMSolverMultistepScheduler-Karras")
135
+ with gr.Row(equal_height=True):
136
+ loras = ['None','add_detail','nayanthara','shobita','surya','vijay','saipallavi']
137
+ lora = gr.Dropdown(label='Lora', choices=loras, value="None")
138
+ lora_weight = gr.Number(value=0.5, minimum=0, maximum=1, step=0.01, label="Lora Weights")
139
+ with gr.Row(equal_height=True):
140
+ btn = gr.Button("Generate", elem_id="run_button")
141
+
142
+ with gr.Column():
143
+ image_out = gr.Image(label="Output", elem_id="output-img", height=1024, width=512)
144
+ btn.click(fn=predict, inputs=[prompt, negative_prompt, guidance_scale, steps, model,scheduler, lora, lora_weight],
145
+ outputs=[image_out], api_name='run')
146
+ prompt.submit(fn=predict, inputs=[prompt, negative_prompt, guidance_scale, steps, model,scheduler, lora, lora_weight],
147
+ outputs=[image_out])
148
+
149
+ image_blocks.queue(max_size=25, api_open=True).launch(show_api=True)
header.html ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div style="text-align: center; max-width: 650px; margin: 0 auto;">
2
+ <div style="
3
+ display: inline-flex;
4
+ gap: 0.8rem;
5
+ font-size: 1.75rem;
6
+ justify-content: center;
7
+ margin-bottom: 10px;
8
+ ">
9
+ <h1 style="font-weight: 900; align-items: center; margin-bottom: 7px; margin-top: 20px;">
10
+ <b>Profaker⛥</b>
11
+ </h1>
12
+ </div>
13
+ </div>
requirements.txt ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --extra-index-url https://download.pytorch.org/whl/cu118
2
+ torch
3
+ git+https://github.com/huggingface/diffusers.git
4
+ transformers
5
+ accelerate
6
+ gradio==3.50.0
7
+ ftfy
8
+ numpy
9
+ matplotlib
10
+ uuid
11
+ opencv-python
12
+ safetensors