Roman Baenro commited on
Commit
ccc900d
1 Parent(s): 500f573

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +166 -0
  2. fetch.py +6 -0
app.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):
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
+ with gr.Blocks() as demo:
58
+ gr.Markdown("""
59
+ # Prodia API web-ui by @zenafey
60
+
61
+ This is simple web-gui for using Prodia API easily, build on Python, gradio, prodiapy
62
+ """)
63
+ with gr.Tab(label="text2img"):
64
+ with gr.Row():
65
+ with gr.Column():
66
+ prompt = gr.Textbox(label="Prompt", lines=2)
67
+ negative = gr.Textbox(label="Negative Prompt", lines=3, placeholder="badly drawn")
68
+
69
+ with gr.Row():
70
+ steps = gr.Slider(label="Steps", value=30, step=1, maximum=50, minimum=1, interactive=True)
71
+ cfg = gr.Slider(label="CFG Scale", maximum=20, minimum=1, value=7, interactive=True)
72
+
73
+ with gr.Row():
74
+ num = gr.Slider(label="Number of images", value=1, step=1, minimum=1, interactive=True)
75
+ seed = gr.Slider(label="Seed", value=-1, minimum=-1, maximum=4294967295, interactive=True)
76
+
77
+ with gr.Row():
78
+ model = gr.Dropdown(label="Model", choices=get_values()[0], value="v1-5-pruned-emaonly.ckpt [81761151]", interactive=True)
79
+ sampler = gr.Dropdown(label="Sampler", choices=get_values()[1], value="DDIM", interactive=True)
80
+
81
+ with gr.Row():
82
+ ar = gr.Radio(label="Aspect Ratio", choices=["square", "portrait", "landscape"], value="square", interactive=True)
83
+ with gr.Column():
84
+ upscale = gr.Checkbox(label="upscale", interactive=True)
85
+ save = gr.Checkbox(label="auto save", interactive=True)
86
+
87
+ with gr.Row():
88
+ run_btn = gr.Button("Run", variant="primary")
89
+ with gr.Column():
90
+ result_image = gr.Gallery(label="Result Image(s)")
91
+ run_btn.click(
92
+ process_input_text2img,
93
+ inputs=[
94
+ prompt,
95
+ negative,
96
+ steps,
97
+ cfg,
98
+ num,
99
+ seed,
100
+ model,
101
+ sampler,
102
+ ar,
103
+ upscale,
104
+ save
105
+ ],
106
+ outputs=[result_image],
107
+ )
108
+
109
+ with gr.Tab(label="img2img"):
110
+ with gr.Row():
111
+ with gr.Column():
112
+ prompt = gr.Textbox(label="Prompt", lines=2)
113
+
114
+ with gr.Row():
115
+ negative = gr.Textbox(label="Negative Prompt", lines=3, placeholder="badly drawn")
116
+ init_image = gr.Textbox(label="Init Image Url", lines=2, placeholder="https://cdn.openai.com/API/images/guides/image_generation_simple.webp")
117
+
118
+
119
+ with gr.Row():
120
+ steps = gr.Slider(label="Steps", value=30, step=1, maximum=50, minimum=1, interactive=True)
121
+ cfg = gr.Slider(label="CFG Scale", maximum=20, minimum=1, value=7, interactive=True)
122
+
123
+ with gr.Row():
124
+ num = gr.Slider(label="Number of images", value=1, step=1, minimum=1, interactive=True)
125
+ seed = gr.Slider(label="Seed", value=-1, minimum=-1, maximum=4294967295, interactive=True)
126
+
127
+ with gr.Row():
128
+ model = gr.Dropdown(label="Model", choices=get_values()[0], value="v1-5-pruned-emaonly.ckpt [81761151]", interactive=True)
129
+ sampler = gr.Dropdown(label="Sampler", choices=get_values()[1], value="DDIM", interactive=True)
130
+
131
+ with gr.Row():
132
+ ds = gr.Slider(label="Denoising strength", maximum=0.9, minimum=0.1, value=0.5, interactive=True)
133
+ with gr.Column():
134
+ upscale = gr.Checkbox(label="upscale", interactive=True)
135
+ save = gr.Checkbox(label="auto save", interactive=True)
136
+
137
+ with gr.Row():
138
+ run_btn = gr.Button("Run", variant="primary")
139
+ with gr.Column():
140
+ result_image = gr.Gallery(label="Result Image(s)")
141
+ run_btn.click(
142
+ process_input_img2img,
143
+ inputs=[
144
+ init_image,
145
+ prompt,
146
+ negative,
147
+ steps,
148
+ cfg,
149
+ num,
150
+ seed,
151
+ model,
152
+ sampler,
153
+ ds,
154
+ upscale,
155
+ save
156
+ ],
157
+ outputs=[result_image],
158
+ )
159
+
160
+ with gr.Tab(label="controlnet(coming soon)"):
161
+ gr.Button(label="lol")
162
+
163
+
164
+ if __name__ == "__main__":
165
+ demo.launch(show_api=True)
166
+
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":"hello@prodia.com"},"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
+