Spaces:
Running
Running
Update README.md
Browse files
README.md
CHANGED
@@ -8,359 +8,3 @@ sdk: gradio
|
|
8 |
pinned: false
|
9 |
app_file: space.py
|
10 |
---
|
11 |
-
|
12 |
-
# `gradio_workflowbuilder`
|
13 |
-
<img alt="Static Badge" src="https://img.shields.io/badge/version%20-%200.0.1%20-%20orange">
|
14 |
-
|
15 |
-
workflow builder
|
16 |
-
|
17 |
-
## Installation
|
18 |
-
|
19 |
-
```bash
|
20 |
-
pip install gradio_workflowbuilder
|
21 |
-
```
|
22 |
-
|
23 |
-
## Usage
|
24 |
-
|
25 |
-
```python
|
26 |
-
import gradio as gr
|
27 |
-
from gradio_workflowbuilder import WorkflowBuilder
|
28 |
-
import json
|
29 |
-
|
30 |
-
|
31 |
-
def export_workflow(workflow_data):
|
32 |
-
"""Export workflow as formatted JSON"""
|
33 |
-
if not workflow_data:
|
34 |
-
return "No workflow to export"
|
35 |
-
return json.dumps(workflow_data, indent=2)
|
36 |
-
|
37 |
-
|
38 |
-
# Create the main interface
|
39 |
-
with gr.Blocks(
|
40 |
-
title="🎨 Visual Workflow Builder",
|
41 |
-
theme=gr.themes.Soft(),
|
42 |
-
css="""
|
43 |
-
.main-container { max-width: 1600px; margin: 0 auto; }
|
44 |
-
.workflow-section { margin-bottom: 2rem; }
|
45 |
-
.button-row { display: flex; gap: 1rem; justify-content: center; margin: 1rem 0; }
|
46 |
-
|
47 |
-
.component-description {
|
48 |
-
padding: 24px;
|
49 |
-
background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
|
50 |
-
border-radius: 12px;
|
51 |
-
border-left: 4px solid #3b82f6;
|
52 |
-
margin: 16px 0;
|
53 |
-
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
|
54 |
-
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
|
55 |
-
}
|
56 |
-
|
57 |
-
.component-description p {
|
58 |
-
margin: 10px 0;
|
59 |
-
line-height: 1.6;
|
60 |
-
color: #374151;
|
61 |
-
}
|
62 |
-
|
63 |
-
.base-description {
|
64 |
-
font-size: 17px;
|
65 |
-
font-weight: 600;
|
66 |
-
color: #1e293b;
|
67 |
-
}
|
68 |
-
|
69 |
-
.base-description strong {
|
70 |
-
color: #3b82f6;
|
71 |
-
font-weight: 700;
|
72 |
-
}
|
73 |
-
|
74 |
-
.feature-description {
|
75 |
-
font-size: 16px;
|
76 |
-
color: #1e293b;
|
77 |
-
font-weight: 500;
|
78 |
-
}
|
79 |
-
|
80 |
-
.customization-note {
|
81 |
-
font-size: 15px;
|
82 |
-
color: #64748b;
|
83 |
-
font-style: italic;
|
84 |
-
}
|
85 |
-
|
86 |
-
.sample-intro {
|
87 |
-
font-size: 15px;
|
88 |
-
color: #1e293b;
|
89 |
-
font-weight: 600;
|
90 |
-
margin-top: 16px;
|
91 |
-
border-top: 1px solid #e2e8f0;
|
92 |
-
padding-top: 16px;
|
93 |
-
}
|
94 |
-
"""
|
95 |
-
) as demo:
|
96 |
-
|
97 |
-
with gr.Column(elem_classes=["main-container"]):
|
98 |
-
gr.Markdown("""
|
99 |
-
# 🎨 Visual Workflow Builder
|
100 |
-
|
101 |
-
**Create sophisticated workflows with drag and drop simplicity.**
|
102 |
-
""")
|
103 |
-
|
104 |
-
# Simple description section with styling
|
105 |
-
gr.HTML("""
|
106 |
-
<div class="component-description">
|
107 |
-
<p class="base-description">Base custom component powered by <strong>svelteflow</strong>.</p>
|
108 |
-
<p class="feature-description">Create custom workflows.</p>
|
109 |
-
<p class="customization-note">You can customise the nodes as well as the design of the workflow.</p>
|
110 |
-
<p class="sample-intro">Here is a sample:</p>
|
111 |
-
</div>
|
112 |
-
""")
|
113 |
-
|
114 |
-
# Main workflow builder section
|
115 |
-
with gr.Column(elem_classes=["workflow-section"]):
|
116 |
-
workflow_builder = WorkflowBuilder(
|
117 |
-
label="🎨 Visual Workflow Designer",
|
118 |
-
info="Drag components from the sidebar → Connect nodes by dragging from output (right) to input (left) → Click nodes to edit properties"
|
119 |
-
)
|
120 |
-
|
121 |
-
# Export section below the workflow
|
122 |
-
gr.Markdown("## 💾 Export Workflow")
|
123 |
-
|
124 |
-
with gr.Row():
|
125 |
-
with gr.Column():
|
126 |
-
export_output = gr.Code(
|
127 |
-
language="json",
|
128 |
-
label="Workflow Configuration",
|
129 |
-
lines=10
|
130 |
-
)
|
131 |
-
|
132 |
-
# Action button
|
133 |
-
with gr.Row(elem_classes=["button-row"]):
|
134 |
-
export_btn = gr.Button("💾 Export JSON", variant="primary", size="lg")
|
135 |
-
|
136 |
-
# Instructions
|
137 |
-
with gr.Accordion("📖 How to Use", open=False):
|
138 |
-
gr.Markdown("""
|
139 |
-
### 🚀 Getting Started
|
140 |
-
|
141 |
-
1. **Add Components**: Drag items from the left sidebar onto the canvas
|
142 |
-
2. **Connect Nodes**: Drag from the blue circle on the right of a node to the left circle of another
|
143 |
-
3. **Edit Properties**: Click any node to see its editable properties on the right panel
|
144 |
-
4. **Organize**: Drag nodes around to create a clean workflow layout
|
145 |
-
5. **Delete**: Use the ✕ button on nodes or click the red circle on connections
|
146 |
-
|
147 |
-
### 🎯 Component Types
|
148 |
-
|
149 |
-
- **📥 Inputs**: Text fields, file uploads, number inputs
|
150 |
-
- **⚙️ Processing**: Language models, text processors, conditionals
|
151 |
-
- **📤 Outputs**: Text displays, file exports, charts
|
152 |
-
- **🔧 Tools**: API calls, data transformers, validators
|
153 |
-
|
154 |
-
### 💡 Pro Tips
|
155 |
-
|
156 |
-
- **Collapsible Panels**: Use the arrow buttons to hide/show sidebars
|
157 |
-
- **Live Updates**: Properties update in real-time as you edit
|
158 |
-
- **Export Options**: Get JSON config for your workflow
|
159 |
-
""")
|
160 |
-
|
161 |
-
# Event handlers
|
162 |
-
export_btn.click(
|
163 |
-
fn=export_workflow,
|
164 |
-
inputs=[workflow_builder],
|
165 |
-
outputs=[export_output]
|
166 |
-
)
|
167 |
-
|
168 |
-
|
169 |
-
if __name__ == "__main__":
|
170 |
-
demo.launch(
|
171 |
-
server_name="0.0.0.0",
|
172 |
-
show_error=True
|
173 |
-
)
|
174 |
-
|
175 |
-
```
|
176 |
-
|
177 |
-
## `WorkflowBuilder`
|
178 |
-
|
179 |
-
### Initialization
|
180 |
-
|
181 |
-
<table>
|
182 |
-
<thead>
|
183 |
-
<tr>
|
184 |
-
<th align="left">name</th>
|
185 |
-
<th align="left" style="width: 25%;">type</th>
|
186 |
-
<th align="left">default</th>
|
187 |
-
<th align="left">description</th>
|
188 |
-
</tr>
|
189 |
-
</thead>
|
190 |
-
<tbody>
|
191 |
-
<tr>
|
192 |
-
<td align="left"><code>value</code></td>
|
193 |
-
<td align="left" style="width: 25%;">
|
194 |
-
|
195 |
-
```python
|
196 |
-
typing.Optional[typing.Dict[str, typing.Any]][
|
197 |
-
typing.Dict[str, typing.Any][str, typing.Any], None
|
198 |
-
]
|
199 |
-
```
|
200 |
-
|
201 |
-
</td>
|
202 |
-
<td align="left"><code>None</code></td>
|
203 |
-
<td align="left">Default workflow data with nodes and edges</td>
|
204 |
-
</tr>
|
205 |
-
|
206 |
-
<tr>
|
207 |
-
<td align="left"><code>label</code></td>
|
208 |
-
<td align="left" style="width: 25%;">
|
209 |
-
|
210 |
-
```python
|
211 |
-
typing.Optional[str][str, None]
|
212 |
-
```
|
213 |
-
|
214 |
-
</td>
|
215 |
-
<td align="left"><code>None</code></td>
|
216 |
-
<td align="left">Component label</td>
|
217 |
-
</tr>
|
218 |
-
|
219 |
-
<tr>
|
220 |
-
<td align="left"><code>info</code></td>
|
221 |
-
<td align="left" style="width: 25%;">
|
222 |
-
|
223 |
-
```python
|
224 |
-
typing.Optional[str][str, None]
|
225 |
-
```
|
226 |
-
|
227 |
-
</td>
|
228 |
-
<td align="left"><code>None</code></td>
|
229 |
-
<td align="left">Additional component information</td>
|
230 |
-
</tr>
|
231 |
-
|
232 |
-
<tr>
|
233 |
-
<td align="left"><code>show_label</code></td>
|
234 |
-
<td align="left" style="width: 25%;">
|
235 |
-
|
236 |
-
```python
|
237 |
-
typing.Optional[bool][bool, None]
|
238 |
-
```
|
239 |
-
|
240 |
-
</td>
|
241 |
-
<td align="left"><code>None</code></td>
|
242 |
-
<td align="left">Whether to show the label</td>
|
243 |
-
</tr>
|
244 |
-
|
245 |
-
<tr>
|
246 |
-
<td align="left"><code>container</code></td>
|
247 |
-
<td align="left" style="width: 25%;">
|
248 |
-
|
249 |
-
```python
|
250 |
-
bool
|
251 |
-
```
|
252 |
-
|
253 |
-
</td>
|
254 |
-
<td align="left"><code>True</code></td>
|
255 |
-
<td align="left">Whether to use container styling</td>
|
256 |
-
</tr>
|
257 |
-
|
258 |
-
<tr>
|
259 |
-
<td align="left"><code>scale</code></td>
|
260 |
-
<td align="left" style="width: 25%;">
|
261 |
-
|
262 |
-
```python
|
263 |
-
typing.Optional[int][int, None]
|
264 |
-
```
|
265 |
-
|
266 |
-
</td>
|
267 |
-
<td align="left"><code>None</code></td>
|
268 |
-
<td align="left">Relative width scale</td>
|
269 |
-
</tr>
|
270 |
-
|
271 |
-
<tr>
|
272 |
-
<td align="left"><code>min_width</code></td>
|
273 |
-
<td align="left" style="width: 25%;">
|
274 |
-
|
275 |
-
```python
|
276 |
-
int
|
277 |
-
```
|
278 |
-
|
279 |
-
</td>
|
280 |
-
<td align="left"><code>160</code></td>
|
281 |
-
<td align="left">Minimum width in pixels</td>
|
282 |
-
</tr>
|
283 |
-
|
284 |
-
<tr>
|
285 |
-
<td align="left"><code>visible</code></td>
|
286 |
-
<td align="left" style="width: 25%;">
|
287 |
-
|
288 |
-
```python
|
289 |
-
bool
|
290 |
-
```
|
291 |
-
|
292 |
-
</td>
|
293 |
-
<td align="left"><code>True</code></td>
|
294 |
-
<td align="left">Whether component is visible</td>
|
295 |
-
</tr>
|
296 |
-
|
297 |
-
<tr>
|
298 |
-
<td align="left"><code>elem_id</code></td>
|
299 |
-
<td align="left" style="width: 25%;">
|
300 |
-
|
301 |
-
```python
|
302 |
-
typing.Optional[str][str, None]
|
303 |
-
```
|
304 |
-
|
305 |
-
</td>
|
306 |
-
<td align="left"><code>None</code></td>
|
307 |
-
<td align="left">HTML element ID</td>
|
308 |
-
</tr>
|
309 |
-
|
310 |
-
<tr>
|
311 |
-
<td align="left"><code>elem_classes</code></td>
|
312 |
-
<td align="left" style="width: 25%;">
|
313 |
-
|
314 |
-
```python
|
315 |
-
typing.Optional[typing.List[str]][
|
316 |
-
typing.List[str][str], None
|
317 |
-
]
|
318 |
-
```
|
319 |
-
|
320 |
-
</td>
|
321 |
-
<td align="left"><code>None</code></td>
|
322 |
-
<td align="left">CSS classes</td>
|
323 |
-
</tr>
|
324 |
-
|
325 |
-
<tr>
|
326 |
-
<td align="left"><code>render</code></td>
|
327 |
-
<td align="left" style="width: 25%;">
|
328 |
-
|
329 |
-
```python
|
330 |
-
bool
|
331 |
-
```
|
332 |
-
|
333 |
-
</td>
|
334 |
-
<td align="left"><code>True</code></td>
|
335 |
-
<td align="left">Whether to render immediately</td>
|
336 |
-
</tr>
|
337 |
-
</tbody></table>
|
338 |
-
|
339 |
-
|
340 |
-
### Events
|
341 |
-
|
342 |
-
| name | description |
|
343 |
-
|:-----|:------------|
|
344 |
-
| `change` | Triggered when the value of the WorkflowBuilder changes either because of user input (e.g. a user types in a textbox) OR because of a function update (e.g. an image receives a value from the output of an event trigger). See `.input()` for a listener that is only triggered by user input. |
|
345 |
-
| `input` | This listener is triggered when the user changes the value of the WorkflowBuilder. |
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
### User function
|
350 |
-
|
351 |
-
The impact on the users predict function varies depending on whether the component is used as an input or output for an event (or both).
|
352 |
-
|
353 |
-
- When used as an Input, the component only impacts the input signature of the user function.
|
354 |
-
- When used as an output, the component only impacts the return signature of the user function.
|
355 |
-
|
356 |
-
The code snippet below is accurate in cases where the component is used as both an input and an output.
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
```python
|
361 |
-
def predict(
|
362 |
-
value: typing.Dict[str, typing.Any][str, typing.Any]
|
363 |
-
) -> typing.Dict[str, typing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