Manikandan-Alagu commited on
Commit
138d871
·
verified ·
1 Parent(s): aca8bd7

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +204 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,204 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+ import io
4
+ import random
5
+ import os
6
+ from PIL import Image
7
+
8
+ list_models = [
9
+ "SDXL-1.0",
10
+ "SD-1.5",
11
+ "OpenJourney-V4",
12
+ "Anything-V4",
13
+ "Disney-Pixar-Cartoon",
14
+ "Pixel-Art-XL",
15
+ "Dalle-3-XL",
16
+ "Midjourney-V4-XL",
17
+ ]
18
+
19
+ def generate_txt2img(current_model, prompt, is_negative=False, image_style="None style", steps=50, cfg_scale=7,
20
+ seed=None):
21
+
22
+ if current_model == "SD-1.5":
23
+ API_URL = "https://api-inference.huggingface.co/models/runwayml/stable-diffusion-v1-5"
24
+ elif current_model == "SDXL-1.0":
25
+ API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl-base-1.0"
26
+ elif current_model == "OpenJourney-V4":
27
+ API_URL = "https://api-inference.huggingface.co/models/prompthero/openjourney"
28
+ elif current_model == "Anything-V4":
29
+ API_URL = "https://api-inference.huggingface.co/models/xyn-ai/anything-v4.0"
30
+ elif current_model == "Disney-Pixar-Cartoon":
31
+ API_URL = "https://api-inference.huggingface.co/models/stablediffusionapi/disney-pixar-cartoon"
32
+ elif current_model == "Pixel-Art-XL":
33
+ API_URL = "https://api-inference.huggingface.co/models/nerijs/pixel-art-xl"
34
+ elif current_model == "Dalle-3-XL":
35
+ API_URL = "https://api-inference.huggingface.co/models/openskyml/dalle-3-xl"
36
+ elif current_model == "Midjourney-V4-XL":
37
+ API_URL = "https://api-inference.huggingface.co/models/openskyml/midjourney-v4-xl"
38
+
39
+ API_TOKEN = os.environ.get("HF_READ_TOKEN")
40
+ headers = {"Authorization": f"Bearer {API_TOKEN}"}
41
+
42
+
43
+ if image_style == "None style":
44
+ payload = {
45
+ "inputs": prompt + ", 8k",
46
+ "is_negative": is_negative,
47
+ "steps": steps,
48
+ "cfg_scale": cfg_scale,
49
+ "seed": seed if seed is not None else random.randint(-1, 2147483647)
50
+ }
51
+ elif image_style == "Cinematic":
52
+ payload = {
53
+ "inputs": prompt + ", realistic, detailed, textured, skin, hair, eyes, by Alex Huguet, Mike Hill, Ian Spriggs, JaeCheol Park, Marek Denko",
54
+ "is_negative": is_negative + ", abstract, cartoon, stylized",
55
+ "steps": steps,
56
+ "cfg_scale": cfg_scale,
57
+ "seed": seed if seed is not None else random.randint(-1, 2147483647)
58
+ }
59
+ elif image_style == "Digital Art":
60
+ payload = {
61
+ "inputs": prompt + ", faded , vintage , nostalgic , by Jose Villa , Elizabeth Messina , Ryan Brenizer , Jonas Peterson , Jasmine Star",
62
+ "is_negative": is_negative + ", sharp , modern , bright",
63
+ "steps": steps,
64
+ "cfg_scale": cfg_scale,
65
+ "seed": seed if seed is not None else random.randint(-1, 2147483647)
66
+ }
67
+ elif image_style == "Portrait":
68
+ payload = {
69
+ "inputs": prompt + ", soft light, sharp, exposure blend, medium shot, bokeh, (hdr:1.4), high contrast, (cinematic, teal and orange:0.85), (muted colors, dim colors, soothing tones:1.3), low saturation, (hyperdetailed:1.2), (noir:0.4), (natural skin texture, hyperrealism, soft light, sharp:1.2)",
70
+ "is_negative": is_negative,
71
+ "steps": steps,
72
+ "cfg_scale": cfg_scale,
73
+ "seed": seed if seed is not None else random.randint(-1, 2147483647)
74
+ }
75
+
76
+ image_bytes = requests.post(API_URL, headers=headers, json=payload).content
77
+ image = Image.open(io.BytesIO(image_bytes))
78
+ return image
79
+
80
+
81
+ css = """
82
+ /* General Container Styles */
83
+ .gradio-container {
84
+ font-family: 'IBM Plex Sans', sans-serif;
85
+ max-width: 730px !important;
86
+ margin: auto;
87
+ padding-top: 1.5rem;
88
+ }
89
+
90
+ /* Button Styles */
91
+ .gr-button {
92
+ color: white;
93
+ border-color: black;
94
+ background: black;
95
+ white-space: nowrap;
96
+ }
97
+
98
+ .gr-button:focus {
99
+ border-color: rgb(147 197 253 / var(--tw-border-opacity));
100
+ outline: none;
101
+ box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000);
102
+ --tw-border-opacity: 1;
103
+ --tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);
104
+ --tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(3px var(--tw-ring-offset-width)) var(--tw-ring-color);
105
+ --tw-ring-color: rgb(191 219 254 / var(--tw-ring-opacity));
106
+ --tw-ring-opacity: .5;
107
+ }
108
+
109
+ /* Footer Styles */
110
+ .footer, .dark .footer {
111
+ margin-bottom: 45px;
112
+ margin-top: 35px;
113
+ text-align: center;
114
+ border-bottom: 1px solid #e5e5e5;
115
+ }
116
+
117
+ .footer > p, .dark .footer > p {
118
+ font-size: .8rem;
119
+ display: inline-block;
120
+ padding: 0 10px;
121
+ transform: translateY(10px);
122
+ background: white;
123
+ }
124
+
125
+ .dark .footer {
126
+ border-color: #303030;
127
+ }
128
+
129
+ .dark .footer > p {
130
+ background: #0b0f19;
131
+ }
132
+
133
+ /* Share Button Styles */
134
+ #share-btn-container {
135
+ padding: 0 0.5rem !important;
136
+ background-color: #000000;
137
+ justify-content: center;
138
+ align-items: center;
139
+ border-radius: 9999px !important;
140
+ max-width: 13rem;
141
+ margin-left: auto;
142
+ }
143
+
144
+ #share-btn-container:hover {
145
+ background-color: #060606;
146
+ }
147
+
148
+ #share-btn {
149
+ all: initial;
150
+ color: #ffffff;
151
+ font-weight: 600;
152
+ cursor: pointer;
153
+ font-family: 'IBM Plex Sans', sans-serif;
154
+ margin-left: 0.5rem !important;
155
+ padding: 0.5rem !important;
156
+ right: 0;
157
+ }
158
+
159
+ /* Animation Styles */
160
+ .animate-spin {
161
+ animation: spin 1s linear infinite;
162
+ }
163
+
164
+ @keyframes spin {
165
+ from { transform: rotate(0deg); }
166
+ to { transform: rotate(360deg); }
167
+ }
168
+
169
+ /* Other Styles */
170
+ #gallery {
171
+ min-height: 22rem;
172
+ margin-bottom: 15px;
173
+ margin-left: auto;
174
+ margin-right: auto;
175
+ border-bottom-right-radius: .5rem !important;
176
+ border-bottom-left-radius: .5rem !important;
177
+ }
178
+ """
179
+
180
+ with gr.Blocks(css=css) as demo:
181
+
182
+ favicon = '<img src="" width="48px" style="display: inline">'
183
+ gr.Markdown(
184
+ f"""<h1><center>{favicon} AI Diffusion</center></h1>
185
+ """
186
+ )
187
+
188
+ with gr.Row(elem_id="prompt-container"):
189
+ current_model = gr.Dropdown(label="Current Model", choices=list_models, value=list_models[1])
190
+
191
+ with gr.Row(elem_id="prompt-container"):
192
+ text_prompt = gr.Textbox(label="Prompt", placeholder="a cute dog", lines=1, elem_id="prompt-text-input")
193
+ text_button = gr.Button("Generate", variant='primary', elem_id="gen-button")
194
+
195
+ with gr.Row():
196
+ image_output = gr.Image(type="pil", label="Output Image", elem_id="gallery")
197
+
198
+ with gr.Accordion("Advanced settings", open=False):
199
+ negative_prompt = gr.Textbox(label="Negative Prompt", value="text, blurry, fuzziness", lines=1, elem_id="negative-prompt-text-input")
200
+ image_style = gr.Dropdown(label="Style", choices=["None style", "Cinematic", "Digital Art", "Portrait"], value="None style", allow_custom_value=False)
201
+
202
+ text_button.click(generate_txt2img, inputs=[current_model, text_prompt, negative_prompt, image_style], outputs=image_output)
203
+
204
+ demo.launch(show_api=False)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ requests
2
+ pillow