Commit
•
e748e0f
1
Parent(s):
0c57aea
Update app.py
Browse files
app.py
CHANGED
@@ -8,6 +8,7 @@ import os
|
|
8 |
import re
|
9 |
|
10 |
import nltk
|
|
|
11 |
|
12 |
import pandas as pd
|
13 |
import streamlit as st
|
@@ -171,6 +172,73 @@ class Application:
|
|
171 |
|
172 |
self.workflow = Workflow(tasks)
|
173 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
174 |
def find(self, key):
|
175 |
"""
|
176 |
Lookup record from cached data by uid key.
|
@@ -271,12 +339,19 @@ class Application:
|
|
271 |
st.sidebar.markdown("---")
|
272 |
|
273 |
with st.sidebar:
|
|
|
|
|
274 |
# Build or re-build workflow when build button clicked
|
275 |
-
build =
|
276 |
if build:
|
277 |
with st.spinner("Building workflow...."):
|
278 |
self.build(components)
|
279 |
|
|
|
|
|
|
|
|
|
|
|
280 |
with st.expander("Data", expanded=not self.data):
|
281 |
data = st.text_area("Input", height=10)
|
282 |
|
|
|
8 |
import re
|
9 |
|
10 |
import nltk
|
11 |
+
import yaml
|
12 |
|
13 |
import pandas as pd
|
14 |
import streamlit as st
|
|
|
172 |
|
173 |
self.workflow = Workflow(tasks)
|
174 |
|
175 |
+
def yaml(self, components):
|
176 |
+
"""
|
177 |
+
Builds a yaml string for components.
|
178 |
+
|
179 |
+
Args:
|
180 |
+
components: list of components to export to YAML
|
181 |
+
|
182 |
+
Returns:
|
183 |
+
YAML string
|
184 |
+
"""
|
185 |
+
|
186 |
+
# pylint: disable=W0108
|
187 |
+
data = {}
|
188 |
+
tasks = []
|
189 |
+
name = None
|
190 |
+
|
191 |
+
for component in components:
|
192 |
+
component = dict(component)
|
193 |
+
name = wtype = component.pop("type")
|
194 |
+
|
195 |
+
if wtype == "summary":
|
196 |
+
data["summary"] = {"path": component.pop("path")}
|
197 |
+
tasks.append({"action": "summary"})
|
198 |
+
|
199 |
+
elif wtype == "segment":
|
200 |
+
data["segmentation"] = component
|
201 |
+
tasks.append({"action": "segmentation"})
|
202 |
+
|
203 |
+
elif wtype == "service":
|
204 |
+
config = dict(**component)
|
205 |
+
config["task"] = "service"
|
206 |
+
tasks.append(config)
|
207 |
+
|
208 |
+
elif wtype == "tabular":
|
209 |
+
data["tabular"] = component
|
210 |
+
tasks.append({"action": "tabular"})
|
211 |
+
|
212 |
+
elif wtype == "textract":
|
213 |
+
data["textractor"] = component
|
214 |
+
tasks.append({"action": "textractor", "task": "url"})
|
215 |
+
|
216 |
+
elif wtype == "transcribe":
|
217 |
+
data["transcription"] = {"path": component.pop("path")}
|
218 |
+
tasks.append({"action": "transcription", "task": "url"})
|
219 |
+
|
220 |
+
elif wtype == "translate":
|
221 |
+
data["translation"] = {}
|
222 |
+
tasks.append({"action": "translation", "args": list(component.values())})
|
223 |
+
|
224 |
+
elif wtype == "embeddings":
|
225 |
+
index = component.pop("index")
|
226 |
+
upsert = component.pop("upsert")
|
227 |
+
|
228 |
+
data["embeddings"] = component
|
229 |
+
data["writable"] = True
|
230 |
+
|
231 |
+
if index:
|
232 |
+
data["path"] = index
|
233 |
+
|
234 |
+
name = "index"
|
235 |
+
tasks.append({"action": "upsert" if upsert else "index"})
|
236 |
+
|
237 |
+
# Add in workflow
|
238 |
+
data["workflow"] = {name: {"tasks": tasks}}
|
239 |
+
|
240 |
+
return (name, yaml.dump(data))
|
241 |
+
|
242 |
def find(self, key):
|
243 |
"""
|
244 |
Lookup record from cached data by uid key.
|
|
|
339 |
st.sidebar.markdown("---")
|
340 |
|
341 |
with st.sidebar:
|
342 |
+
col1, col2 = st.columns(2)
|
343 |
+
|
344 |
# Build or re-build workflow when build button clicked
|
345 |
+
build = col1.button("Build", help="Build the workflow and run within this application")
|
346 |
if build:
|
347 |
with st.spinner("Building workflow...."):
|
348 |
self.build(components)
|
349 |
|
350 |
+
# Generate API configuration
|
351 |
+
_, config = self.yaml(components)
|
352 |
+
|
353 |
+
col2.download_button("Export", config, file_name="workflow.yml", mime="text/yaml", help="Export the API workflow as YAML")
|
354 |
+
|
355 |
with st.expander("Data", expanded=not self.data):
|
356 |
data = st.text_area("Input", height=10)
|
357 |
|