Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -5,39 +5,31 @@ import random
|
|
5 |
import os
|
6 |
from PIL import Image
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
"
|
11 |
-
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
"inputs": prompt,
|
21 |
-
"is_negative": is_negative,
|
22 |
-
"steps": steps,
|
23 |
-
"cfg_scale": cfg_scale,
|
24 |
-
"seed": seed if seed is not None else random.randint(-1, 2147483647)
|
25 |
-
}
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
elif image_style == "Portrait":
|
36 |
-
base_payload["inputs"] += ", 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)"
|
37 |
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
|
42 |
css = """
|
43 |
/* General Container Styles */
|
@@ -46,12 +38,13 @@ css = """
|
|
46 |
max-width: 730px !important;
|
47 |
margin: auto;
|
48 |
padding-top: 1.5rem;
|
49 |
-
text-align: center;
|
50 |
}
|
|
|
51 |
/* Button Styles */
|
52 |
.gr-button {
|
53 |
color: white;
|
54 |
-
background: #007bff;
|
55 |
white-space: nowrap;
|
56 |
border: none;
|
57 |
padding: 10px 20px;
|
@@ -59,23 +52,27 @@ css = """
|
|
59 |
cursor: pointer;
|
60 |
transition: background-color 0.3s, color 0.3s;
|
61 |
}
|
|
|
62 |
.gr-button:hover {
|
63 |
-
background-color: #0056b3;
|
64 |
}
|
|
|
65 |
/* Share Button Styles */
|
66 |
#share-btn-container {
|
67 |
padding: 0.5rem !important;
|
68 |
-
background-color: #007bff;
|
69 |
justify-content: center;
|
70 |
align-items: center;
|
71 |
border-radius: 9999px !important;
|
72 |
max-width: 13rem;
|
73 |
-
margin: 0 auto;
|
74 |
transition: background-color 0.3s;
|
75 |
}
|
|
|
76 |
#share-btn-container:hover {
|
77 |
-
background-color: #0056b3;
|
78 |
}
|
|
|
79 |
#share-btn {
|
80 |
all: initial;
|
81 |
color: #ffffff;
|
@@ -85,54 +82,38 @@ css = """
|
|
85 |
margin: 0.5rem !important;
|
86 |
padding: 0.5rem !important;
|
87 |
}
|
|
|
88 |
/* Other Styles */
|
89 |
#gallery {
|
90 |
min-height: 22rem;
|
91 |
-
margin: auto;
|
92 |
border-bottom-right-radius: 0.5rem !important;
|
93 |
border-bottom-left-radius: 0.5rem !important;
|
94 |
}
|
95 |
-
|
96 |
.image-container {
|
97 |
-
max-width: 100%;
|
98 |
-
margin: auto;
|
99 |
-
padding: 20px;
|
100 |
-
border: 1px solid #ccc;
|
101 |
border-radius: 10px;
|
102 |
-
overflow: hidden;
|
103 |
-
max-height: 22rem;
|
104 |
-
|
105 |
-
|
106 |
.image-container img {
|
107 |
-
max-width: 100%;
|
108 |
-
height: auto;
|
109 |
-
max-height: 100%;
|
110 |
border-radius: 10px;
|
111 |
box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.2);
|
112 |
}
|
113 |
"""
|
114 |
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
gr.Markdown("<h1>PixelCraft</h1>")
|
121 |
-
current_model = gr.Dropdown(label="Select Model", choices=list_models, value=list_models[0])
|
122 |
-
text_prompt = gr.Textbox(label="Enter Prompt", placeholder="Example: a cute dog", lines=2)
|
123 |
-
generate_button = gr.Button("Generate Image", variant='primary')
|
124 |
-
|
125 |
-
with gr.Column():
|
126 |
-
gr.Markdown("<h4>Advanced Settings</h4>")
|
127 |
-
with gr.Accordion("Advanced Customizations", open=False):
|
128 |
-
negative_prompt = gr.Textbox(label="Negative Prompt (Optional)", placeholder="Example: blurry, unfocused", lines=2)
|
129 |
-
image_style = gr.Dropdown(label="Select Style", choices=["None style", "Cinematic", "Digital Art", "Portrait"], value="None style")
|
130 |
-
# Add more options if needed
|
131 |
-
|
132 |
-
with gr.Row():
|
133 |
-
image_output = gr.Image(type="pil", label="Output Image")
|
134 |
-
|
135 |
-
generate_button.click(generate_txt2img, inputs=[current_model, text_prompt, negative_prompt, image_style], outputs=image_output)
|
136 |
|
137 |
-
|
138 |
-
demo.launch()
|
|
|
5 |
import os
|
6 |
from PIL import Image
|
7 |
|
8 |
+
def generate_txt2img(prompt, is_negative=False, image_style="None style", steps=50, cfg_scale=7, seed=None):
|
9 |
+
API_URL = "https://api-inference.huggingface.co/models/MysteriousAI/NSFW-gen"
|
10 |
+
API_TOKEN = os.getenv("HF_READ_TOKEN")
|
11 |
+
headers = {"Authorization": f"Bearer {API_TOKEN}"}
|
12 |
|
13 |
+
base_payload = {
|
14 |
+
"inputs": prompt,
|
15 |
+
"is_negative": is_negative,
|
16 |
+
"steps": steps,
|
17 |
+
"cfg_scale": cfg_scale,
|
18 |
+
"seed": seed if seed is not None else random.randint(-1, 2147483647)
|
19 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
+
if image_style == "Cinematic":
|
22 |
+
base_payload["inputs"] += ", realistic, detailed, textured, skin, hair, eyes, by Alex Huguet, Mike Hill, Ian Spriggs, JaeCheol Park, Marek Denko"
|
23 |
+
base_payload["is_negative"] += ", abstract, cartoon, stylized"
|
24 |
+
elif image_style == "Digital Art":
|
25 |
+
base_payload["inputs"] += ", faded , vintage , nostalgic , by Jose Villa , Elizabeth Messina , Ryan Brenizer , Jonas Peterson , Jasmine Star"
|
26 |
+
base_payload["is_negative"] += ", sharp , modern , bright"
|
27 |
+
elif image_style == "Portrait":
|
28 |
+
base_payload["inputs"] += ", 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)"
|
|
|
|
|
29 |
|
30 |
+
image_bytes = requests.post(API_URL, headers=headers, json=base_payload).content
|
31 |
+
image = Image.open(io.BytesIO(image_bytes))
|
32 |
+
return image
|
33 |
|
34 |
css = """
|
35 |
/* General Container Styles */
|
|
|
38 |
max-width: 730px !important;
|
39 |
margin: auto;
|
40 |
padding-top: 1.5rem;
|
41 |
+
text-align: center;
|
42 |
}
|
43 |
+
|
44 |
/* Button Styles */
|
45 |
.gr-button {
|
46 |
color: white;
|
47 |
+
background: #007bff;
|
48 |
white-space: nowrap;
|
49 |
border: none;
|
50 |
padding: 10px 20px;
|
|
|
52 |
cursor: pointer;
|
53 |
transition: background-color 0.3s, color 0.3s;
|
54 |
}
|
55 |
+
|
56 |
.gr-button:hover {
|
57 |
+
background-color: #0056b3;
|
58 |
}
|
59 |
+
|
60 |
/* Share Button Styles */
|
61 |
#share-btn-container {
|
62 |
padding: 0.5rem !important;
|
63 |
+
background-color: #007bff;
|
64 |
justify-content: center;
|
65 |
align-items: center;
|
66 |
border-radius: 9999px !important;
|
67 |
max-width: 13rem;
|
68 |
+
margin: 0 auto;
|
69 |
transition: background-color 0.3s;
|
70 |
}
|
71 |
+
|
72 |
#share-btn-container:hover {
|
73 |
+
background-color: #0056b3;
|
74 |
}
|
75 |
+
|
76 |
#share-btn {
|
77 |
all: initial;
|
78 |
color: #ffffff;
|
|
|
82 |
margin: 0.5rem !important;
|
83 |
padding: 0.5rem !important;
|
84 |
}
|
85 |
+
|
86 |
/* Other Styles */
|
87 |
#gallery {
|
88 |
min-height: 22rem;
|
89 |
+
margin: auto;
|
90 |
border-bottom-right-radius: 0.5rem !important;
|
91 |
border-bottom-left-radius: 0.5rem !important;
|
92 |
}
|
93 |
+
|
94 |
.image-container {
|
95 |
+
max-width: 100%;
|
96 |
+
margin: auto;
|
97 |
+
padding: 20px;
|
98 |
+
border: 1px solid #ccc;
|
99 |
border-radius: 10px;
|
100 |
+
overflow: hidden;
|
101 |
+
max-height: 22rem;
|
102 |
+
}
|
103 |
+
|
104 |
.image-container img {
|
105 |
+
max-width: 100%;
|
106 |
+
height: auto;
|
107 |
+
max-height: 100%;
|
108 |
border-radius: 10px;
|
109 |
box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.2);
|
110 |
}
|
111 |
"""
|
112 |
|
113 |
+
demo = gr.Interface(generate_txt2img,
|
114 |
+
inputs=["text", "checkbox", gr.inputs.Dropdown(["None style", "Cinematic", "Digital Art", "Portrait"], label="Select Style")],
|
115 |
+
outputs="image",
|
116 |
+
title="PixelCraft",
|
117 |
+
css=css)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
|
119 |
+
demo.launch()
|
|