Upload 3 files
Browse files- fetch.py +6 -0
- main.py +166 -0
- requirements.txt +4 -0
fetch.py
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
|
3 |
+
def get_values():
|
4 |
+
resp = {"doc":{"metadata":{"image":[],"title":"","description":""},"api":{"method":"post","url":"","auth":"required","params":[],"results":{"codes":[]},"apiSetting":"63e152abae39c70076448b6f"},"swagger":{"path":"/job"},"next":{"description":"","pages":[]},"algolia":{"recordCount":1,"publishPending":False,"updatedAt":"2023-05-13T20:21:27.923Z"},"title":"Create a generation","icon":"","updates":[],"type":"endpoint","slug":"generate","excerpt":"Use this endpoint to start generating an image on Prodia.","body":"","order":0,"isReference":True,"deprecated":False,"hidden":False,"sync_unique":"generate","link_url":"","link_external":False,"previousSlug":"","slugUpdatedAt":"2023-02-06T19:16:54.830Z","revision":63,"_id":"63e152adae39c70076448b76","category":"63e152abae39c70076448b70","createdAt":"2023-02-06T19:19:09.122Z","updatedAt":"2023-07-05T20:56:55.881Z","parentDoc":"63ea65265e3b33000eda4124","project":"63def422013dd3004536bc06","version":{"version":"1.2","version_clean":"1.2.0","codename":"ImageGenie","is_stable":True,"is_beta":True,"is_hidden":False,"is_deprecated":False,"categories":["63def422013dd3004536bc0d","63def422013dd3004536bc0d","63def422013dd3004536bc0f","63def423013dd3004536bc17","63def4ab8570a300596ffa51","63e14c3d7db7ee005f65368e","63e152095cca0b02d7803f6b","63e1523e0de987044faf7119","63e1525b8f256f045a6ae39b","63e152abae39c70076448b70","63e28c3fb119180074e5a342","63e3c154fff713002b0b4b15","63e3c15ef6c1c5001e00a2a7","64020c652839760066ca3c5b"],"_id":"63def422013dd3004536bc0b","project":"63def422013dd3004536bc06","releaseDate":"2023-02-05T00:11:14.850Z","createdAt":"2023-02-05T00:11:14.850Z","__v":1},"__v":0,"isApi":True,"tutorials":[],"id":"63e152adae39c70076448b76"},"hideTOC":False,"meta":{"description":"Use this endpoint to start generating an image on Prodia.","hidden":False,"title":"Create a generation","type":"reference"},"oasDefinition":{"openapi":"3.0.3","info":{"title":"Prodia API","description":"Welcome to Prodia's API :)","termsOfService":"https://app.prodia.com/#/terms-of-service","contact":{"email":"[email protected]"},"version":"1.2.0"},"servers":[{"url":"https://api.prodia.com/v1"}],"tags":[{"name":"Image Generation","description":"Image Generation API"}],"paths":{"/job":{"post":{"tags":["Image Generation"],"summary":"Create a generation","description":"Use this endpoint to start generating an image on Prodia.","operationId":"generate","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/GenerateRequest"}}},"required":True},"responses":{"200":{"description":"Success","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Job"}}}},"400":{"description":"Invalid Generation Parameters"},"401":{"description":"Key Not Recognised"},"402":{"description":"API Access Not Enabled"}}}},"/transform":{"post":{"tags":["Image Generation"],"summary":"Transform an existing image","description":"Use this endpoint to do an 'img2img' style generation.","operationId":"transform","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/TransformRequest"}}},"required":True},"responses":{"200":{"description":"Success","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Job"}}}},"400":{"description":"Invalid Generation Parameters"},"401":{"description":"Key Not Recognised"},"402":{"description":"API Access Not Enabled"}}}},"/controlnet":{"post":{"tags":["Image Generation"],"summary":"[Coming soon] Create a Controlnet generation","description":"Use this endpoint to do a Controlnet generation.","operationId":"controlnet","requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ControlNetRequest"}}},"required":True},"responses":{"200":{"description":"Success","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Job"}}}},"400":{"description":"Invalid Generation Parameters"},"401":{"description":"Key Not Recognised"},"402":{"description":"API Access Not Enabled"}}}},"/job/{jobId}":{"get":{"parameters":[{"in":"path","name":"jobId","schema":{"type":"string"},"required":True,"description":"ID of Job"}],"tags":["Image Generation"],"summary":"Retrieve a generation","description":"Get information about a generation job, including status.","operationId":"getJob","responses":{"200":{"description":"Success","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Job"}}}},"401":{"description":"Key Not Recognised"},"402":{"description":"API Access Not Enabled"}}}}},"components":{"securitySchemes":{"ApiKeyAuth":{"type":"apiKey","in":"header","name":"X-Prodia-Key"}},"schemas":{"Model":{"enum":["analog-diffusion-1.0.ckpt [9ca13f02]","anythingv3_0-pruned.ckpt [2700c435]","anything-v4.5-pruned.ckpt [65745d25]","AOM3A3_orangemixs.safetensors [9600da17]","deliberate_v2.safetensors [10ec4b29]","dreamlike-diffusion-1.0.safetensors [5c9fd6e0]","dreamlike-diffusion-2.0.safetensors [fdcf65e7]","dreamshaper_5BakedVae.safetensors [a3fbf318]","dreamshaper_6BakedVae.safetensors [114c8abb]","elldreths-vivid-mix.safetensors [342d9d26]","lyriel_v15.safetensors [65d547c5]","lyriel_v16.safetensors [68fceea2]","mechamix_v10.safetensors [ee685731]","meinamix_meinaV9.safetensors [2ec66ab0]","openjourney_V4.ckpt [ca2f377f]","portrait+1.0.safetensors [1400e684]","Realistic_Vision_V1.4-pruned-fp16.safetensors [8d21810b]","Realistic_Vision_V2.0.safetensors [79587710]","revAnimated_v122.safetensors [3f4fefd9]","riffusion-model-v1.ckpt [3aafa6fe]","sdv1_4.ckpt [7460a6fa]","v1-5-pruned-emaonly.ckpt [81761151]","shoninsBeautiful_v10.safetensors [25d8c546]","theallys-mix-ii-churned.safetensors [5d9225a4]","timeless-1.0.ckpt [7c4971d4]"]},"ControlnetModel":{"enum":["control_v11p_sd15_softedge [a8575a2a]","control_v11p_sd15_mlsd [aca30ff0]","control_v11e_sd15_ip2p [c4bb465c]","control_v11p_sd15_seg [e1f51eb9]","control_v11p_sd15_inpaint [ebff9138]","control_v11p_sd15s2_lineart_anime [3825e83e]","control_v11e_sd15_shuffle [526bfdae]","control_v11p_sd15_canny [d14c016b]","control_v11p_sd15_lineart [43d4be0d]","control_v11p_sd15_normalbae [316696f1]","control_v11f1p_sd15_depth [cfd03158]","control_v11p_sd15_openpose [cab727d4]","control_v11f1e_sd15_tile [a371b31b]","control_v11p_sd15_scribble [d4ba51ff]"]},"Sampler":{"enum":["Euler","Euler a","Heun","DPM++ 2M Karras","DDIM"]},"Job":{"type":"object","properties":{"job":{"type":"string","example":"xxxx-xxxx-xxxx-xxxx","description":"Job ID"},"params":{"type":"object","example":"{}","description":"Job Generation Params"},"status":{"enum":["queued","generating","failed","succeeded"]},"imageUrl":{"type":"string","description":"Direct URL to generated image"}}},"GenerateRequest":{"type":"object","required":["prompt"],"properties":{"model":{"$ref":"#/components/schemas/Model"},"prompt":{"type":"string","example":"puppies in a cloud, 4k","description":"Image Prompt"},"negative_prompt":{"type":"string","example":"badly drawn","description":"Negative Image Prompt"},"steps":{"type":"number","example":25,"description":"Steps"},"cfg_scale":{"type":"number","example":7,"description":"CFG Scale"},"seed":{"type":"number","example":-1,"description":"Seed"},"upscale":{"type":"boolean","example":False,"description":"Enable 2x Upscale"},"sampler":{"$ref":"#/components/schemas/Sampler"},"aspect_ratio":{"enum":["square","portrait","landscape"]}}},"TransformRequest":{"type":"object","required":["prompt","imageUrl"],"properties":{"imageUrl":{"type":"string","example":"https://example.com/image.png","description":"Input Image URL"},"model":{"$ref":"#/components/schemas/Model"},"prompt":{"type":"string","example":"puppies in a cloud, 4k","description":"Image Prompt"},"denoising_strength":{"type":"number","example":0.7,"description":"Strength of image transfomation"},"negative_prompt":{"type":"string","example":"badly drawn","description":"Negative Image Prompt"},"steps":{"type":"number","example":25,"description":"Steps"},"cfg_scale":{"type":"number","example":7,"description":"CFG Scale"},"seed":{"type":"number","example":-1,"description":"Seed"},"upscale":{"type":"boolean","example":False,"description":"Enable 2x Upscale"},"sampler":{"$ref":"#/components/schemas/Sampler"}}},"ControlNetRequest":{"type":"object","required":["prompt","imageUrl"],"properties":{"imageUrl":{"type":"string","example":"https://example.com/image.png","description":"Input Image URL"},"controlnet_model":{"$ref":"#/components/schemas/ControlnetModel"},"prompt":{"type":"string","example":"puppies in a cloud, 4k","description":"Image Prompt"},"negative_prompt":{"type":"string","example":"badly drawn","description":"Negative Image Prompt"},"steps":{"type":"number","example":25,"description":"Steps"},"cfg_scale":{"type":"number","example":7,"description":"CFG Scale"},"seed":{"type":"number","example":-1,"description":"Seed"},"sampler":{"$ref":"#/components/schemas/Sampler"}}}}},"security":[{"ApiKeyAuth":[]}],"x-readme":{"explorer-enabled":True,"proxy-enabled":True,"samples-enabled":True},"_id":"63e152abae39c70076448b6f"},"oasPublicUrl":"@prodia/v1.2#edaualjq791p4","oauth":True,"loginUrl":"https://app.prodia.com/api","suggestedEdits":True}
|
5 |
+
return [resp["oasDefinition"]["components"]["schemas"]['Model']['enum'], resp["oasDefinition"]["components"]["schemas"]['Sampler']['enum']]
|
6 |
+
|
main.py
ADDED
@@ -0,0 +1,166 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
prodia_key = os.getenv('PRODIA_X_KEY', None)
|
12 |
+
if prodia_key is None:
|
13 |
+
print("Please set PRODIA_X_KEY in .env, closing...")
|
14 |
+
exit()
|
15 |
+
client = prodia.Client(api_key=prodia_key)
|
16 |
+
|
17 |
+
def process_input_text2img(prompt, negative_prompt, steps, cfg_scale, number, seed, model, sampler, aspect_ratio, upscale, save=False):
|
18 |
+
images = []
|
19 |
+
for image in range(number):
|
20 |
+
result = client.txt2img(prompt=prompt, negative_prompt=negative_prompt, model=model, sampler=sampler,
|
21 |
+
steps=steps, cfg_scale=cfg_scale, seed=seed, aspect_ratio=aspect_ratio, upscale=upscale)
|
22 |
+
images.append(result.url)
|
23 |
+
if save:
|
24 |
+
date = datetime.now()
|
25 |
+
if not os.path.isdir(f'./outputs/{date.year}-{date.month}-{date.day}'):
|
26 |
+
os.mkdir(f'./outputs/{date.year}-{date.month}-{date.day}')
|
27 |
+
img_data = requests.get(result.url).content
|
28 |
+
with open(f"./outputs/{date.year}-{date.month}-{date.day}/{random.randint(1, 10000000000000)}_{result.seed}.png", "wb") as f:
|
29 |
+
f.write(img_data)
|
30 |
+
return images
|
31 |
+
|
32 |
+
def process_input_img2img(init, prompt, negative_prompt, steps, cfg_scale, number, seed, model, sampler, ds, upscale, save):
|
33 |
+
images = []
|
34 |
+
for image in range(number):
|
35 |
+
result = client.img2img(imageUrl=init, prompt=prompt, negative_prompt=negative_prompt, model=model, sampler=sampler,
|
36 |
+
steps=steps, cfg_scale=cfg_scale, seed=seed, denoising_strength=ds, upscale=upscale)
|
37 |
+
images.append(result.url)
|
38 |
+
if save:
|
39 |
+
date = datetime.now()
|
40 |
+
if not os.path.isdir(f'./outputs/{date.year}-{date.month}-{date.day}'):
|
41 |
+
os.mkdir(f'./outputs/{date.year}-{date.month}-{date.day}')
|
42 |
+
img_data = requests.get(result.url).content
|
43 |
+
with open(f"./outputs/{date.year}-{date.month}-{date.day}/{random.randint(1, 10000000000000)}_{result.seed}.png", "wb") as f:
|
44 |
+
f.write(img_data)
|
45 |
+
return images
|
46 |
+
|
47 |
+
"""
|
48 |
+
def process_input_control(init, prompt, negative_prompt, steps, cfg_scale, number, seed, model, control_model, sampler):
|
49 |
+
images = []
|
50 |
+
for image in range(number):
|
51 |
+
result = client.controlnet(imageUrl=init, prompt=prompt, negative_prompt=negative_prompt, model=model, sampler=sampler,
|
52 |
+
steps=steps, cfg_scale=cfg_scale, seed=seed, controlnet_model=control_model)
|
53 |
+
images.append(result.url)
|
54 |
+
return images
|
55 |
+
"""
|
56 |
+
|
57 |
+
theme = gr.themes.Base(
|
58 |
+
primary_hue=gr.themes.Color(c100="#dbeafe", c200="#bfdbfe", c300="#93c5fd", c400="#60a5fa", c50="#eff6ff", c500="#3b82f6", c600="#2563eb", c700="#fb3657", c800="#1e40af", c900="#1e3a8a", c950="#1d3660"),
|
59 |
+
neutral_hue=gr.themes.Color(c100="#e0e7ff", c200="#c7d2fe", c300="#3c4367", c400="#b5b5b5", c50="#eef2ff", c500="#757575", c600="#221935", c700="#09001b", c800="#0f0e27", c900="#0f0e27", c950="#09001b"),
|
60 |
+
).set(
|
61 |
+
block_background_fill='*background_fill_secondary'
|
62 |
+
)
|
63 |
+
|
64 |
+
|
65 |
+
with gr.Blocks(theme=theme) as demo:
|
66 |
+
gr.Markdown("""
|
67 |
+
# Prodia by @xAbdoAT
|
68 |
+
|
69 |
+
This is simple web-gui for using Prodia API easily, build on Python, gradio, prodiapy
|
70 |
+
""")
|
71 |
+
with gr.Tab(label="text2img"):
|
72 |
+
with gr.Row():
|
73 |
+
with gr.Column():
|
74 |
+
prompt = gr.Textbox(label="Prompt", lines=2, placeholder="puppies in a cloud, 4k")
|
75 |
+
negative = gr.Textbox(label="Negative Prompt", lines=3, placeholder="Add words you don't want to show up in your art...")
|
76 |
+
|
77 |
+
with gr.Row():
|
78 |
+
steps = gr.Slider(label="Steps", value=30, step=1, maximum=50, minimum=1, interactive=True)
|
79 |
+
cfg = gr.Slider(label="CFG Scale", maximum=20, minimum=1, value=7, interactive=True)
|
80 |
+
|
81 |
+
with gr.Row():
|
82 |
+
num = gr.Slider(label="Number of images", value=1, step=1, minimum=1, interactive=True)
|
83 |
+
seed = gr.Slider(label="Seed", value=-1, minimum=-1, maximum=4294967295, interactive=True)
|
84 |
+
|
85 |
+
with gr.Row():
|
86 |
+
model = gr.Dropdown(label="Model", choices=get_values()[0], value="v1-5-pruned-emaonly.ckpt [81761151]", interactive=True)
|
87 |
+
sampler = gr.Dropdown(label="Sampler", choices=get_values()[1], value="DDIM", interactive=True)
|
88 |
+
|
89 |
+
with gr.Row():
|
90 |
+
ar = gr.Radio(label="Aspect Ratio", choices=["square", "portrait", "landscape"], value="square", interactive=True)
|
91 |
+
with gr.Column():
|
92 |
+
upscale = gr.Checkbox(label="upscale", interactive=True)
|
93 |
+
|
94 |
+
with gr.Row():
|
95 |
+
run_btn = gr.Button("Run", variant="primary")
|
96 |
+
with gr.Column():
|
97 |
+
result_image = gr.Gallery(label="Result Image(s)")
|
98 |
+
run_btn.click(
|
99 |
+
process_input_text2img,
|
100 |
+
inputs=[
|
101 |
+
prompt,
|
102 |
+
negative,
|
103 |
+
steps,
|
104 |
+
cfg,
|
105 |
+
num,
|
106 |
+
seed,
|
107 |
+
model,
|
108 |
+
sampler,
|
109 |
+
ar,
|
110 |
+
upscale
|
111 |
+
],
|
112 |
+
outputs=[result_image],
|
113 |
+
)
|
114 |
+
|
115 |
+
with gr.Tab(label="img2img"):
|
116 |
+
with gr.Row():
|
117 |
+
with gr.Column():
|
118 |
+
prompt = gr.Textbox(label="Prompt", lines=2, placeholder="puppies in a cloud, 4k")
|
119 |
+
|
120 |
+
with gr.Row():
|
121 |
+
negative = gr.Textbox(label="Negative Prompt", lines=3, placeholder="Add words you don't want to show up in your art...")
|
122 |
+
init_image = gr.Textbox(label="Init Image Url", lines=2, placeholder="https://cdn.openai.com/API/images/guides/image_generation_simple.webp")
|
123 |
+
|
124 |
+
|
125 |
+
with gr.Row():
|
126 |
+
steps = gr.Slider(label="Steps", value=30, step=1, maximum=50, minimum=1, interactive=True)
|
127 |
+
cfg = gr.Slider(label="CFG Scale", maximum=20, minimum=1, value=7, interactive=True)
|
128 |
+
|
129 |
+
with gr.Row():
|
130 |
+
num = gr.Slider(label="Number of images", value=1, step=1, minimum=1, interactive=True)
|
131 |
+
seed = gr.Slider(label="Seed", value=-1, minimum=-1, maximum=4294967295, interactive=True)
|
132 |
+
|
133 |
+
with gr.Row():
|
134 |
+
model = gr.Dropdown(label="Model", choices=get_values()[0], value="v1-5-pruned-emaonly.ckpt [81761151]", interactive=True)
|
135 |
+
sampler = gr.Dropdown(label="Sampler", choices=get_values()[1], value="DDIM", interactive=True)
|
136 |
+
|
137 |
+
with gr.Row():
|
138 |
+
ds = gr.Slider(label="Denoising strength", maximum=0.9, minimum=0.1, value=0.5, interactive=True)
|
139 |
+
with gr.Column():
|
140 |
+
upscale = gr.Checkbox(label="upscale", interactive=True)
|
141 |
+
|
142 |
+
|
143 |
+
with gr.Row():
|
144 |
+
run_btn = gr.Button("Run", variant="primary")
|
145 |
+
with gr.Column():
|
146 |
+
result_image = gr.Gallery(label="Result Image(s)")
|
147 |
+
run_btn.click(
|
148 |
+
process_input_img2img,
|
149 |
+
inputs=[
|
150 |
+
init_image,
|
151 |
+
prompt,
|
152 |
+
negative,
|
153 |
+
steps,
|
154 |
+
cfg,
|
155 |
+
num,
|
156 |
+
seed,
|
157 |
+
model,
|
158 |
+
sampler,
|
159 |
+
ds,
|
160 |
+
upscale
|
161 |
+
],
|
162 |
+
outputs=[result_image],
|
163 |
+
)
|
164 |
+
|
165 |
+
if __name__ == "__main__":
|
166 |
+
demo.launch(show_api=True)
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
requests
|
3 |
+
python-dotenv
|
4 |
+
prodiapy
|