Commit
·
2ef1b3c
1
Parent(s):
5dec1fe
Update app.py
Browse files
app.py
CHANGED
@@ -8,7 +8,6 @@ import os
|
|
8 |
import re
|
9 |
|
10 |
import nltk
|
11 |
-
import yaml
|
12 |
|
13 |
import pandas as pd
|
14 |
import streamlit as st
|
@@ -180,65 +179,6 @@ class Application:
|
|
180 |
|
181 |
self.workflow = Workflow(tasks)
|
182 |
|
183 |
-
def yaml(self, components):
|
184 |
-
"""
|
185 |
-
Builds a yaml string for components.
|
186 |
-
|
187 |
-
Args:
|
188 |
-
components: list of components to export to YAML
|
189 |
-
|
190 |
-
Returns:
|
191 |
-
YAML string
|
192 |
-
"""
|
193 |
-
|
194 |
-
# pylint: disable=W0108
|
195 |
-
data = {}
|
196 |
-
tasks = []
|
197 |
-
name = None
|
198 |
-
|
199 |
-
for component in components:
|
200 |
-
component = dict(component)
|
201 |
-
name = wtype = component.pop("type")
|
202 |
-
|
203 |
-
if wtype == "summary":
|
204 |
-
data["summary"] = {"path": component.pop("path")}
|
205 |
-
tasks.append({"action": "summary"})
|
206 |
-
|
207 |
-
elif wtype == "segment":
|
208 |
-
data["segmentation"] = component
|
209 |
-
tasks.append({"action": "segmentation"})
|
210 |
-
|
211 |
-
elif wtype == "service":
|
212 |
-
config = dict(**component)
|
213 |
-
config["task"] = "service"
|
214 |
-
tasks.append(config)
|
215 |
-
|
216 |
-
elif wtype == "tabular":
|
217 |
-
data["tabular"] = component
|
218 |
-
tasks.append({"action": "tabular"})
|
219 |
-
|
220 |
-
elif wtype == "transcribe":
|
221 |
-
data["transcription"] = {"path": component.pop("path")}
|
222 |
-
tasks.append({"action": "transcription", "task": "url"})
|
223 |
-
|
224 |
-
elif wtype == "translate":
|
225 |
-
data["translation"] = {}
|
226 |
-
tasks.append({"action": "translation", "args": list(component.values())})
|
227 |
-
|
228 |
-
elif wtype == "embeddings":
|
229 |
-
upsert = component.pop("upsert")
|
230 |
-
|
231 |
-
data["embeddings"] = component
|
232 |
-
data["writable"] = True
|
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,19 +279,12 @@ class Application:
|
|
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 =
|
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 |
|
|
|
8 |
import re
|
9 |
|
10 |
import nltk
|
|
|
11 |
|
12 |
import pandas as pd
|
13 |
import streamlit as st
|
|
|
179 |
|
180 |
self.workflow = Workflow(tasks)
|
181 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
182 |
def find(self, key):
|
183 |
"""
|
184 |
Lookup record from cached data by uid key.
|
|
|
279 |
st.sidebar.markdown("---")
|
280 |
|
281 |
with st.sidebar:
|
|
|
|
|
282 |
# Build or re-build workflow when build button clicked
|
283 |
+
build = st.button("Build", help="Build the workflow and run within this application")
|
284 |
if build:
|
285 |
with st.spinner("Building workflow...."):
|
286 |
self.build(components)
|
287 |
|
|
|
|
|
|
|
|
|
|
|
288 |
with st.expander("Data", expanded=not self.data):
|
289 |
data = st.text_area("Input", height=10)
|
290 |
|