akhil20187 commited on
Commit
6f1ec06
·
verified ·
1 Parent(s): d2832da

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +68 -0
  2. comicidapi.json +209 -0
app.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from PIL import Image
3
+ import numpy as np
4
+ import os
5
+ import json
6
+ import tempfile
7
+ import replicate # type: ignore
8
+
9
+
10
+ file_path = "comicidapi.json"
11
+ # Define the replicate API token
12
+ auth_token = os.environ.get("REPLICATE_API_TOKEN")
13
+ print (auth_token)
14
+
15
+
16
+ def load_workflow_from_file(file_path):
17
+ with open(file_path, 'r') as file:
18
+ return json.load(file)
19
+
20
+ def process_image(image, style, character, prompt1):
21
+ workflow = dict()
22
+ pil_image = Image.fromarray((image))
23
+
24
+ prompt = f"Generate an image based on {style} style, graphic novel art, character as {character}, with high resolution, UHD, background of the image as {prompt1}"
25
+
26
+ # Save the image to a temporary file
27
+ with tempfile.NamedTemporaryFile(suffix=".jpg", delete=False) as temp_file:
28
+ pil_image = Image.fromarray(image)
29
+ pil_image.save(temp_file.name)
30
+ print (temp_file.name)
31
+ input_file = open(f"{temp_file.name}", "rb")
32
+
33
+ workflow = load_workflow_from_file(file_path)
34
+ workflow["6"]["inputs"]["text"] = f"{prompt}" #prompt
35
+
36
+
37
+ # Define the API endpoind
38
+ output = replicate.run(
39
+ "fofr/any-comfyui-workflow:68ece9a0cd9b8de5708e012f64fa5deccd1ab7571a2e207cac0bd463b7107e79",
40
+ input = {
41
+ "workflow_json": json.dumps(workflow),
42
+ "randomise_seeds": True,
43
+ "return_temp_files": False,
44
+ "input_file": input_file
45
+ },
46
+ )
47
+ print(output)
48
+ return(output[0])
49
+
50
+
51
+ iface = gr.Interface(
52
+ fn=process_image,
53
+ inputs=[
54
+ gr.Image(label = "Upload your Image"),
55
+ gr.Dropdown(choices=["Graphic Illustration","Anime", "ComicStrip", "Disney", "Pixar 3D", "Pixel Art", "Gothic", "Chibi"," Oil Painting"], label="Style"),
56
+ gr.Dropdown(choices=["SuperMan","Cinderrella","SnowWhite","Elsa Frozen", "Batman", "Ariel Mermaid", "Wonder Woman", "Iron-Man","Spider-Man","Captain America","Batgirl","Blackwidow","Hulk"], label="Character"),
57
+ gr.Textbox(lines=2, placeholder="Enter your prompt here...", label="Describe the background of the image")
58
+ ],
59
+ outputs=[
60
+ gr.Image(label="Your transformed Image")
61
+ ],
62
+ title="Image Processing App",
63
+ description="Select a style, character, and enter a prompt to process the image.\n In case of any error, try again with a better quality image where the face is clear and with better resolution",
64
+
65
+ )
66
+
67
+ # Launch the Gradio app
68
+ iface.launch()
comicidapi.json ADDED
@@ -0,0 +1,209 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "3": {
3
+ "inputs": {
4
+ "seed": 31657616060644,
5
+ "steps": 30,
6
+ "cfg": 6,
7
+ "sampler_name": "euler_ancestral",
8
+ "scheduler": "karras",
9
+ "denoise": 1,
10
+ "model": [
11
+ "10",
12
+ 0
13
+ ],
14
+ "positive": [
15
+ "10",
16
+ 1
17
+ ],
18
+ "negative": [
19
+ "10",
20
+ 2
21
+ ],
22
+ "latent_image": [
23
+ "5",
24
+ 0
25
+ ]
26
+ },
27
+ "class_type": "KSampler",
28
+ "_meta": {
29
+ "title": "KSampler"
30
+ }
31
+ },
32
+ "4": {
33
+ "inputs": {
34
+ "ckpt_name": "ProteusV0.4.safetensors"
35
+ },
36
+ "class_type": "CheckpointLoaderSimple",
37
+ "_meta": {
38
+ "title": "Load Checkpoint"
39
+ }
40
+ },
41
+ "5": {
42
+ "inputs": {
43
+ "width": 1024,
44
+ "height": 1024,
45
+ "batch_size": 1
46
+ },
47
+ "class_type": "EmptyLatentImage",
48
+ "_meta": {
49
+ "title": "Empty Latent Image"
50
+ }
51
+ },
52
+ "6": {
53
+ "inputs": {
54
+ "text": "{{prompt}}",
55
+ "clip": [
56
+ "4",
57
+ 1
58
+ ]
59
+ },
60
+ "class_type": "CLIPTextEncode",
61
+ "_meta": {
62
+ "title": "CLIP Text Encode (Prompt)"
63
+ }
64
+ },
65
+ "7": {
66
+ "inputs": {
67
+ "text": "text, watermark, deformed, blurred, watermarks, deformed fingers, open mouth, lips open",
68
+ "clip": [
69
+ "4",
70
+ 1
71
+ ]
72
+ },
73
+ "class_type": "CLIPTextEncode",
74
+ "_meta": {
75
+ "title": "CLIP Text Encode (Prompt)"
76
+ }
77
+ },
78
+ "8": {
79
+ "inputs": {
80
+ "samples": [
81
+ "3",
82
+ 0
83
+ ],
84
+ "vae": [
85
+ "4",
86
+ 2
87
+ ]
88
+ },
89
+ "class_type": "VAEDecode",
90
+ "_meta": {
91
+ "title": "VAE Decode"
92
+ }
93
+ },
94
+ "10": {
95
+ "inputs": {
96
+ "weight": 0.8,
97
+ "start_at": 0,
98
+ "end_at": 1,
99
+ "instantid": [
100
+ "14",
101
+ 0
102
+ ],
103
+ "insightface": [
104
+ "13",
105
+ 0
106
+ ],
107
+ "control_net": [
108
+ "12",
109
+ 0
110
+ ],
111
+ "image": [
112
+ "17",
113
+ 0
114
+ ],
115
+ "model": [
116
+ "4",
117
+ 0
118
+ ],
119
+ "positive": [
120
+ "6",
121
+ 0
122
+ ],
123
+ "negative": [
124
+ "7",
125
+ 0
126
+ ]
127
+ },
128
+ "class_type": "ApplyInstantID",
129
+ "_meta": {
130
+ "title": "Apply InstantID"
131
+ }
132
+ },
133
+ "12": {
134
+ "inputs": {
135
+ "control_net_name": "instantid/diffusion_pytorch_model.safetensors"
136
+ },
137
+ "class_type": "ControlNetLoader",
138
+ "_meta": {
139
+ "title": "Load ControlNet Model"
140
+ }
141
+ },
142
+ "13": {
143
+ "inputs": {
144
+ "provider": "CPU"
145
+ },
146
+ "class_type": "InstantIDFaceAnalysis",
147
+ "_meta": {
148
+ "title": "InstantID Face Analysis"
149
+ }
150
+ },
151
+ "14": {
152
+ "inputs": {
153
+ "instantid_file": "instantid-ip-adapter.bin"
154
+ },
155
+ "class_type": "InstantIDModelLoader",
156
+ "_meta": {
157
+ "title": "Load InstantID Model"
158
+ }
159
+ },
160
+ "15": {
161
+ "inputs": {
162
+ "image": "input.jpg",
163
+ "upload": "image"
164
+ },
165
+ "class_type": "LoadImage",
166
+ "_meta": {
167
+ "title": "Load Image"
168
+ }
169
+ },
170
+ "17": {
171
+ "inputs": {
172
+ "crop_padding_factor": 0.650000000000000,
173
+ "cascade_xml": "lbpcascade_animeface.xml",
174
+ "image": [
175
+ "15",
176
+ 0
177
+ ]
178
+ },
179
+ "class_type": "Image Crop Face",
180
+ "_meta": {
181
+ "title": "Image Crop Face"
182
+ }
183
+ },
184
+ "18": {
185
+ "inputs": {
186
+ "images": [
187
+ "17",
188
+ 0
189
+ ]
190
+ },
191
+ "class_type": "PreviewImage",
192
+ "_meta": {
193
+ "title": "Preview Image"
194
+ }
195
+ },
196
+ "20": {
197
+ "inputs": {
198
+ "filename_prefix": "akhi",
199
+ "images": [
200
+ "8",
201
+ 0
202
+ ]
203
+ },
204
+ "class_type": "SaveImage",
205
+ "_meta": {
206
+ "title": "Save Image"
207
+ }
208
+ }
209
+ }