Spaces:
Runtime error
Runtime error
Commit
·
1f522d7
1
Parent(s):
b76033f
Delete main.py
Browse files
main.py
DELETED
|
@@ -1,242 +0,0 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
from fetch import get_values
|
| 3 |
-
from dotenv import load_dotenv
|
| 4 |
-
load_dotenv()
|
| 5 |
-
import prodia
|
| 6 |
-
import requests
|
| 7 |
-
import random
|
| 8 |
-
from datetime import datetime
|
| 9 |
-
import os
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
prodia_key = os.getenv('PRODIA_X_KEY', None)
|
| 13 |
-
if prodia_key is None:
|
| 14 |
-
print("Please set PRODIA_X_KEY in .env, closing...")
|
| 15 |
-
exit()
|
| 16 |
-
client = prodia.Client(api_key=prodia_key)
|
| 17 |
-
|
| 18 |
-
def process_input_text2img(prompt, negative_prompt, steps, cfg_scale, number, seed, model, sampler, aspect_ratio, upscale, save=False):
|
| 19 |
-
images = []
|
| 20 |
-
for image in range(number):
|
| 21 |
-
result = client.sd_generate(prompt=prompt, negative_prompt=negative_prompt, model=model, sampler=sampler,
|
| 22 |
-
steps=steps, cfg_scale=cfg_scale, seed=seed, aspect_ratio=aspect_ratio, upscale=upscale)
|
| 23 |
-
images.append(result.url)
|
| 24 |
-
if save:
|
| 25 |
-
date = datetime.now()
|
| 26 |
-
if not os.path.isdir(f'./outputs/{date.year}-{date.month}-{date.day}'):
|
| 27 |
-
os.mkdir(f'./outputs/{date.year}-{date.month}-{date.day}')
|
| 28 |
-
img_data = requests.get(result.url).content
|
| 29 |
-
with open(f"./outputs/{date.year}-{date.month}-{date.day}/{random.randint(1, 10000000000000)}_{result.seed}.png", "wb") as f:
|
| 30 |
-
f.write(img_data)
|
| 31 |
-
return images
|
| 32 |
-
|
| 33 |
-
def process_input_img2img(init, prompt, negative_prompt, steps, cfg_scale, number, seed, model, sampler, ds, upscale, save):
|
| 34 |
-
images = []
|
| 35 |
-
for image in range(number):
|
| 36 |
-
result = client.sd_transform(imageUrl=init, prompt=prompt, negative_prompt=negative_prompt, model=model, sampler=sampler,
|
| 37 |
-
steps=steps, cfg_scale=cfg_scale, seed=seed, denoising_strength=ds, upscale=upscale)
|
| 38 |
-
images.append(result.url)
|
| 39 |
-
if save:
|
| 40 |
-
date = datetime.now()
|
| 41 |
-
if not os.path.isdir(f'./outputs/{date.year}-{date.month}-{date.day}'):
|
| 42 |
-
os.mkdir(f'./outputs/{date.year}-{date.month}-{date.day}')
|
| 43 |
-
img_data = requests.get(result.url).content
|
| 44 |
-
with open(f"./outputs/{date.year}-{date.month}-{date.day}/{random.randint(1, 10000000000000)}_{result.seed}.png", "wb") as f:
|
| 45 |
-
f.write(img_data)
|
| 46 |
-
return images
|
| 47 |
-
|
| 48 |
-
"""
|
| 49 |
-
def process_input_control(init, prompt, negative_prompt, steps, cfg_scale, number, seed, model, control_model, sampler):
|
| 50 |
-
images = []
|
| 51 |
-
for image in range(number):
|
| 52 |
-
result = client.controlnet(imageUrl=init, prompt=prompt, negative_prompt=negative_prompt, model=model, sampler=sampler,
|
| 53 |
-
steps=steps, cfg_scale=cfg_scale, seed=seed, controlnet_model=control_model)
|
| 54 |
-
images.append(result.url)
|
| 55 |
-
return images
|
| 56 |
-
"""
|
| 57 |
-
|
| 58 |
-
theme = "Base"
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
with gr.Blocks(theme=theme) as demo:
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
gr.Markdown("""
|
| 67 |
-
# ForgeStudio Large
|
| 68 |
-
|
| 69 |
-
<p></p>
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
""")
|
| 73 |
-
|
| 74 |
-
with gr.Accordion("🆔 Account", open=False):
|
| 75 |
-
with gr.Row():
|
| 76 |
-
gr.LoginButton(size="sm")
|
| 77 |
-
gr.LogoutButton(size="sm")
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
gr.DuplicateButton(value="Duplicate space for private use")
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
with gr.Tab(label="txt2img"):
|
| 87 |
-
with gr.Row():
|
| 88 |
-
with gr.Column():
|
| 89 |
-
prompt = gr.Textbox(label="Prompt", lines=2, placeholder="beautiful cat, 8k")
|
| 90 |
-
negative = gr.Textbox(label="Negative Prompt", lines=3, value="text, blurry, fuzziness", placeholder="Add words you don't want to show up in your art...")
|
| 91 |
-
|
| 92 |
-
with gr.Row():
|
| 93 |
-
steps = gr.Slider(label="Steps", value=25, step=1, maximum=50, minimum=5, interactive=True)
|
| 94 |
-
cfg = gr.Slider(label="CFG Scale", maximum=20, minimum=1, value=7, interactive=True, info="Recommended 7 CFG Scale")
|
| 95 |
-
|
| 96 |
-
with gr.Row():
|
| 97 |
-
num = gr.Slider(label="Number of images", value=1, step=1, maximum=4, minimum=1, interactive=True)
|
| 98 |
-
seed = gr.Slider(label="Seed", value=-1, step=1, minimum=-1, maximum=4294967295, interactive=True, info="""'-1' is a random seed""")
|
| 99 |
-
|
| 100 |
-
with gr.Row():
|
| 101 |
-
model = gr.Dropdown(label="Model", choices=get_values()[0], value="v1-5-pruned-emaonly.ckpt [81761151]", interactive=True)
|
| 102 |
-
sampler = gr.Dropdown(label="Sampler", choices=get_values()[1], value="DPM++ SDE Karras", interactive=True)
|
| 103 |
-
|
| 104 |
-
with gr.Row():
|
| 105 |
-
ar = gr.Radio(label="Aspect Ratio", choices=["square", "portrait", "landscape"], value="square", interactive=True)
|
| 106 |
-
with gr.Column():
|
| 107 |
-
upscale = gr.Checkbox(label="upscale", value=True, interactive=True, info="""'True' recommended, improves image quality""")
|
| 108 |
-
|
| 109 |
-
with gr.Row():
|
| 110 |
-
run_btn = gr.Button("Generate", variant="primary")
|
| 111 |
-
with gr.Column():
|
| 112 |
-
result_image = gr.Gallery(label="Result Image(s)", show_download_button=False, show_share_button=True)
|
| 113 |
-
|
| 114 |
-
with gr.Accordion("📑 Examples", open=False):
|
| 115 |
-
with gr.Row():
|
| 116 |
-
gr.Examples(
|
| 117 |
-
|
| 118 |
-
examples=[
|
| 119 |
-
|
| 120 |
-
["A high tech solarpunk utopia in the Amazon rainforest"],
|
| 121 |
-
["A pikachu fine dining with a view to the Eiffel Tower"],
|
| 122 |
-
["A mecha robot in a favela in expressionist style"],
|
| 123 |
-
["an insect robot preparing a delicious meal"],
|
| 124 |
-
["A small cabin on top of a snowy mountain in the style of Disney, artstation"]
|
| 125 |
-
],
|
| 126 |
-
|
| 127 |
-
inputs=[prompt],
|
| 128 |
-
cache_examples=False,
|
| 129 |
-
)
|
| 130 |
-
|
| 131 |
-
run_btn.click(
|
| 132 |
-
process_input_text2img,
|
| 133 |
-
inputs=[
|
| 134 |
-
prompt,
|
| 135 |
-
negative,
|
| 136 |
-
steps,
|
| 137 |
-
cfg,
|
| 138 |
-
num,
|
| 139 |
-
seed,
|
| 140 |
-
model,
|
| 141 |
-
sampler,
|
| 142 |
-
ar,
|
| 143 |
-
upscale
|
| 144 |
-
],
|
| 145 |
-
outputs=[result_image],
|
| 146 |
-
)
|
| 147 |
-
|
| 148 |
-
with gr.Tab(label="img2img"):
|
| 149 |
-
with gr.Row():
|
| 150 |
-
with gr.Column():
|
| 151 |
-
prompt = gr.Textbox(label="Prompt", lines=2, placeholder="beautiful cat, 8k")
|
| 152 |
-
|
| 153 |
-
with gr.Row():
|
| 154 |
-
negative = gr.Textbox(label="Negative Prompt", lines=3, placeholder="Add words you don't want to show up in your art...")
|
| 155 |
-
|
| 156 |
-
gr.Markdown("""
|
| 157 |
-
|
| 158 |
-
<p></p>
|
| 159 |
-
|
| 160 |
-
⚠️ Attention, only images generated by ForgeStudio Large are accepted, that is, first generate an image in the txt2img section, and then insert a link to this image in the Init Image URL, for example: https://images.prodia.xyz/image.png
|
| 161 |
-
|
| 162 |
-
""")
|
| 163 |
-
|
| 164 |
-
init_image = gr.Textbox(label="Init Image Url", lines=3, placeholder="https://images.prodia.xyz/d372060f-673d-486d-b3a8-f2c8a33f25f3.png")
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
with gr.Row():
|
| 168 |
-
steps = gr.Slider(label="Steps", value=25, step=1, maximum=50, minimum=1, interactive=True)
|
| 169 |
-
cfg = gr.Slider(label="CFG Scale", maximum=20, minimum=1, value=7, interactive=True, info="Recommended 7 CFG Scale")
|
| 170 |
-
|
| 171 |
-
with gr.Row():
|
| 172 |
-
num = gr.Slider(label="Number of images", value=1, step=1, maximum=4, minimum=1, interactive=True)
|
| 173 |
-
seed = gr.Slider(label="Seed", value=-1, step=1, minimum=-1, maximum=4294967295, interactive=True, info="""'-1' is a random seed""")
|
| 174 |
-
|
| 175 |
-
with gr.Row():
|
| 176 |
-
model = gr.Dropdown(label="Model", choices=get_values()[0], value="v1-5-pruned-emaonly.ckpt [81761151]", interactive=True)
|
| 177 |
-
sampler = gr.Dropdown(label="Sampler", choices=get_values()[1], value="DPM++ 2M Karras", interactive=True)
|
| 178 |
-
|
| 179 |
-
with gr.Row():
|
| 180 |
-
ds = gr.Slider(label="Denoising strength", maximum=0.9, minimum=0.1, value=0.5, interactive=True)
|
| 181 |
-
with gr.Column():
|
| 182 |
-
upscale = gr.Checkbox(label="upscale", value=True, interactive=True, info="""'True' recommended, improves image quality""")
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
with gr.Row():
|
| 186 |
-
run_btn = gr.Button("Generate", variant="primary")
|
| 187 |
-
with gr.Column():
|
| 188 |
-
result_image = gr.Gallery(label="Result Image(s)")
|
| 189 |
-
run_btn.click(
|
| 190 |
-
process_input_img2img,
|
| 191 |
-
inputs=[
|
| 192 |
-
init_image,
|
| 193 |
-
prompt,
|
| 194 |
-
negative,
|
| 195 |
-
steps,
|
| 196 |
-
cfg,
|
| 197 |
-
num,
|
| 198 |
-
seed,
|
| 199 |
-
model,
|
| 200 |
-
sampler,
|
| 201 |
-
ds,
|
| 202 |
-
upscale
|
| 203 |
-
],
|
| 204 |
-
outputs=[result_image],
|
| 205 |
-
)
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
with gr.Tab(label="Others"):
|
| 212 |
-
with gr.Tab(label="Image Tools"):
|
| 213 |
-
with gr.Accordion("Remove Background", open=False):
|
| 214 |
-
with gr.Row():
|
| 215 |
-
gr.load("hardon-server/remove-background-on-image-def", src="spaces")
|
| 216 |
-
with gr.Accordion("Flip Image", open=False):
|
| 217 |
-
with gr.Row():
|
| 218 |
-
gr.load("hardon-server/image_flip", src="spaces")
|
| 219 |
-
with gr.Accordion("Sepia Filter", open=False):
|
| 220 |
-
with gr.Row():
|
| 221 |
-
gr.load("hardon-server/sepia_filter", src="spaces")
|
| 222 |
-
with gr.Tab(label="GANs"):
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
with gr.Accordion("RANGAN", open=False):
|
| 226 |
-
with gr.Row():
|
| 227 |
-
gr.load("hardon-server/projected_gan1", src="spaces")
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
with gr.Tab(label="Gallery"):
|
| 234 |
-
|
| 235 |
-
gr.load("nateraw/stable_diffusion_gallery", src="spaces")
|
| 236 |
-
|
| 237 |
-
with gr.Tab(label="License"):
|
| 238 |
-
|
| 239 |
-
gr.load("4com/4com-license", src="spaces")
|
| 240 |
-
|
| 241 |
-
if __name__ == "__main__":
|
| 242 |
-
demo.launch(show_api=False, enable_queue=False, debug=False, share=False, show_error=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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