Spaces:
Running
Running
Upload folder using huggingface_hub
Browse files- main.py +108 -8
- requirements.txt +2 -1
main.py
CHANGED
@@ -6,6 +6,7 @@ from PIL import Image
|
|
6 |
import requests
|
7 |
import dotenv
|
8 |
from io import BytesIO
|
|
|
9 |
# from gradio_imageslider import ImageSlider
|
10 |
|
11 |
dotenv.load_dotenv()
|
@@ -30,11 +31,54 @@ def get_gradio_component(class_type):
|
|
30 |
}
|
31 |
return component_map.get(class_type, gr.Textbox) # Default to Textbox if not found
|
32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
# Function to update inputs
|
34 |
def get_inputs():
|
35 |
res = client.deployment.get_input_definition(id=deployment_id)
|
36 |
input_definitions = res.response_bodies
|
37 |
gradio_inputs = []
|
|
|
38 |
for input_def in input_definitions:
|
39 |
component_class = get_gradio_component(input_def.class_type)
|
40 |
|
@@ -57,21 +101,72 @@ def get_inputs():
|
|
57 |
elif input_def.class_type == 'ComfyUIDeployExternalNumberInt':
|
58 |
kwargs["precision"] = 0
|
59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
# print(kwargs)
|
|
|
|
|
61 |
|
62 |
-
|
63 |
-
|
64 |
-
return gradio_inputs, input_definitions
|
65 |
|
66 |
with gr.Blocks() as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
with gr.Row():
|
68 |
with gr.Column(scale=1):
|
69 |
@gr.render()
|
70 |
def update_inputs():
|
71 |
-
inputs, input_definitions = get_inputs()
|
72 |
submit_button = gr.Button("Submit")
|
73 |
|
74 |
-
async def main(*args):
|
75 |
inputs = {input_def.input_id: arg for input_def, arg in zip(input_definitions, args)}
|
76 |
|
77 |
for key, value in inputs.items():
|
@@ -96,6 +191,8 @@ with gr.Blocks() as demo:
|
|
96 |
if res.object is not None:
|
97 |
res2 = await client.run.get_async(run_id=res.object.run_id)
|
98 |
print("checking ", res2.object.progress, res2.object.live_status)
|
|
|
|
|
99 |
|
100 |
if res2.object is not None and res2.object.status == "success":
|
101 |
# print(res2)
|
@@ -112,15 +209,18 @@ with gr.Blocks() as demo:
|
|
112 |
outputs[1] += "\n\n" + "\n".join(output.data.text)
|
113 |
break
|
114 |
await asyncio.sleep(2)
|
|
|
|
|
|
|
115 |
|
116 |
-
return outputs
|
117 |
|
118 |
-
submit_button.click(fn=main, inputs=inputs, outputs=output_components)
|
119 |
|
120 |
with gr.Column(scale=1):
|
121 |
output_components = [
|
122 |
gr.Gallery(),
|
123 |
-
gr.Textbox(label="Text Output")
|
124 |
]
|
125 |
|
126 |
if __name__ == "__main__":
|
|
|
6 |
import requests
|
7 |
import dotenv
|
8 |
from io import BytesIO
|
9 |
+
import random
|
10 |
# from gradio_imageslider import ImageSlider
|
11 |
|
12 |
dotenv.load_dotenv()
|
|
|
31 |
}
|
32 |
return component_map.get(class_type, gr.Textbox) # Default to Textbox if not found
|
33 |
|
34 |
+
with gr.Blocks() as demo:
|
35 |
+
gr.Markdown("""
|
36 |
+
# ComfyDeploy Gradio Interface
|
37 |
+
|
38 |
+
This is a Gradio interface for a ComfyDeploy workflow. You can interact with the deployed model using the inputs below.
|
39 |
+
|
40 |
+
To clone this workflow, visit: [ComfyDeploy Gradio Flux](https://www.comfydeploy.com/share/comfy-deploy-gradio-flux)
|
41 |
+
|
42 |
+
## Example usage of ComfyDeploy SDK:
|
43 |
+
|
44 |
+
```python
|
45 |
+
from comfydeploy import ComfyDeploy
|
46 |
+
import os
|
47 |
+
|
48 |
+
# Initialize the client
|
49 |
+
client = ComfyDeploy(bearer_auth=os.environ['API_KEY'])
|
50 |
+
|
51 |
+
# Run the model
|
52 |
+
inputs = {
|
53 |
+
'prompt': 'A beautiful landscape',
|
54 |
+
'negative_prompt': 'ugly, blurry',
|
55 |
+
'width': 512,
|
56 |
+
'height': 512
|
57 |
+
}
|
58 |
+
res = client.run.create(
|
59 |
+
request={
|
60 |
+
"deployment_id": deployment_id,
|
61 |
+
"inputs": inputs
|
62 |
+
}
|
63 |
+
)
|
64 |
+
|
65 |
+
# Get the results
|
66 |
+
run_id = res.object.run_id
|
67 |
+
result = client.run.get(run_id=run_id)
|
68 |
+
```
|
69 |
+
""")
|
70 |
+
|
71 |
+
def randomSeed(num_digits=15):
|
72 |
+
range_start = 10 ** (num_digits - 1)
|
73 |
+
range_end = (10**num_digits) - 1
|
74 |
+
return random.randint(range_start, range_end)
|
75 |
+
|
76 |
# Function to update inputs
|
77 |
def get_inputs():
|
78 |
res = client.deployment.get_input_definition(id=deployment_id)
|
79 |
input_definitions = res.response_bodies
|
80 |
gradio_inputs = []
|
81 |
+
random_seeds = []
|
82 |
for input_def in input_definitions:
|
83 |
component_class = get_gradio_component(input_def.class_type)
|
84 |
|
|
|
101 |
elif input_def.class_type == 'ComfyUIDeployExternalNumberInt':
|
102 |
kwargs["precision"] = 0
|
103 |
|
104 |
+
if "seed" in input_def.input_id:
|
105 |
+
with gr.Row():
|
106 |
+
kwargs["value"] = randomSeed()
|
107 |
+
input = component_class(**kwargs, scale=6)
|
108 |
+
randomize_button = gr.Button("Randomize", size="sm")
|
109 |
+
def randomize_seed(input):
|
110 |
+
return randomSeed()
|
111 |
+
randomize_button.click(fn=randomize_seed, inputs=input, outputs=input)
|
112 |
+
gradio_inputs.append(input)
|
113 |
+
random_seeds.append(input)
|
114 |
+
|
115 |
# print(kwargs)
|
116 |
+
else:
|
117 |
+
gradio_inputs.append(component_class(**kwargs))
|
118 |
|
119 |
+
return gradio_inputs, input_definitions, random_seeds
|
|
|
|
|
120 |
|
121 |
with gr.Blocks() as demo:
|
122 |
+
gr.Markdown("""
|
123 |
+
# ComfyDeploy Gradio Interface
|
124 |
+
|
125 |
+
This is a Gradio interface for a ComfyDeploy workflow. You can interact with the deployed model using the inputs below.
|
126 |
+
|
127 |
+
To clone this workflow, visit: [ComfyDeploy Gradio Flux](https://www.comfydeploy.com/share/comfy-deploy-gradio-flux)
|
128 |
+
|
129 |
+
## Example usage of ComfyDeploy SDK:
|
130 |
+
|
131 |
+
```python
|
132 |
+
from comfydeploy import ComfyDeploy
|
133 |
+
import os
|
134 |
+
|
135 |
+
# Initialize the client
|
136 |
+
client = ComfyDeploy(bearer_auth=os.environ['API_KEY'])
|
137 |
+
|
138 |
+
# Get input definitions
|
139 |
+
deployment_id = 'your_deployment_id'
|
140 |
+
res = client.deployment.get_input_definition(id=deployment_id)
|
141 |
+
input_definitions = res.response_bodies
|
142 |
+
|
143 |
+
# Run the model
|
144 |
+
inputs = {
|
145 |
+
'prompt': 'A beautiful landscape',
|
146 |
+
'negative_prompt': 'ugly, blurry',
|
147 |
+
'width': 512,
|
148 |
+
'height': 512
|
149 |
+
}
|
150 |
+
res = client.run.create(
|
151 |
+
request={
|
152 |
+
"deployment_id": deployment_id,
|
153 |
+
"inputs": inputs
|
154 |
+
}
|
155 |
+
)
|
156 |
+
|
157 |
+
# Get the results
|
158 |
+
run_id = res.object.run_id
|
159 |
+
result = client.run.get(run_id=run_id)
|
160 |
+
""")
|
161 |
+
|
162 |
with gr.Row():
|
163 |
with gr.Column(scale=1):
|
164 |
@gr.render()
|
165 |
def update_inputs():
|
166 |
+
inputs, input_definitions, random_seeds = get_inputs()
|
167 |
submit_button = gr.Button("Submit")
|
168 |
|
169 |
+
async def main(*args, progress=gr.Progress()):
|
170 |
inputs = {input_def.input_id: arg for input_def, arg in zip(input_definitions, args)}
|
171 |
|
172 |
for key, value in inputs.items():
|
|
|
191 |
if res.object is not None:
|
192 |
res2 = await client.run.get_async(run_id=res.object.run_id)
|
193 |
print("checking ", res2.object.progress, res2.object.live_status)
|
194 |
+
progress_value = res2.object.progress if res2.object.progress is not None else 0
|
195 |
+
progress(progress_value, desc=f"{res2.object.live_status}")
|
196 |
|
197 |
if res2.object is not None and res2.object.status == "success":
|
198 |
# print(res2)
|
|
|
209 |
outputs[1] += "\n\n" + "\n".join(output.data.text)
|
210 |
break
|
211 |
await asyncio.sleep(2)
|
212 |
+
|
213 |
+
for random_seed in random_seeds:
|
214 |
+
random_seed.value = randomSeed()
|
215 |
|
216 |
+
return outputs + random_seeds
|
217 |
|
218 |
+
submit_button.click(fn=main, inputs=inputs, outputs=output_components+random_seeds)
|
219 |
|
220 |
with gr.Column(scale=1):
|
221 |
output_components = [
|
222 |
gr.Gallery(),
|
223 |
+
gr.Textbox(label="Text Output"),
|
224 |
]
|
225 |
|
226 |
if __name__ == "__main__":
|
requirements.txt
CHANGED
@@ -1,3 +1,4 @@
|
|
1 |
comfydeploy==0.3.4
|
2 |
gradio==4.41.0
|
3 |
-
gradio_imageslider
|
|
|
|
1 |
comfydeploy==0.3.4
|
2 |
gradio==4.41.0
|
3 |
+
gradio_imageslider
|
4 |
+
python-dotenv
|