Commit
·
08d28ec
1
Parent(s):
343c23e
Update app.py
Browse files
app.py
CHANGED
|
@@ -24,18 +24,19 @@ class Process:
|
|
| 24 |
|
| 25 |
@staticmethod
|
| 26 |
@st.cache(ttl=30 * 60, max_entries=3, allow_output_mutation=True, show_spinner=False)
|
| 27 |
-
def get(components):
|
| 28 |
"""
|
| 29 |
Lookup or creates a new workflow process instance.
|
| 30 |
|
| 31 |
Args:
|
| 32 |
components: input components
|
|
|
|
| 33 |
|
| 34 |
Returns:
|
| 35 |
Process
|
| 36 |
"""
|
| 37 |
|
| 38 |
-
process = Process()
|
| 39 |
|
| 40 |
# Build workflow
|
| 41 |
with st.spinner("Building workflow...."):
|
|
@@ -43,9 +44,12 @@ class Process:
|
|
| 43 |
|
| 44 |
return process
|
| 45 |
|
| 46 |
-
def __init__(self):
|
| 47 |
"""
|
| 48 |
Creates a new Process.
|
|
|
|
|
|
|
|
|
|
| 49 |
"""
|
| 50 |
|
| 51 |
# Component options
|
|
@@ -60,7 +64,7 @@ class Process:
|
|
| 60 |
# Embeddings index params
|
| 61 |
self.embeddings = None
|
| 62 |
self.documents = None
|
| 63 |
-
self.data =
|
| 64 |
|
| 65 |
def build(self, components):
|
| 66 |
"""
|
|
@@ -615,12 +619,13 @@ class Application:
|
|
| 615 |
# Wrap data as list for workflow processing
|
| 616 |
return [data]
|
| 617 |
|
| 618 |
-
def query(self, workflow):
|
| 619 |
"""
|
| 620 |
Gets input query.
|
| 621 |
|
| 622 |
Args:
|
| 623 |
workflow: workflow configuration
|
|
|
|
| 624 |
|
| 625 |
Returns:
|
| 626 |
input query
|
|
@@ -629,35 +634,37 @@ class Application:
|
|
| 629 |
default = self.appsetting(workflow, "query")
|
| 630 |
default = default if default else ""
|
| 631 |
|
| 632 |
-
#
|
| 633 |
-
query = st.text_input("Query", value=default)
|
| 634 |
|
| 635 |
# Save query state
|
| 636 |
st.session_state["query"] = query
|
| 637 |
|
| 638 |
return query
|
| 639 |
|
| 640 |
-
def process(self, workflow, components):
|
| 641 |
"""
|
| 642 |
Processes the current application action.
|
| 643 |
|
| 644 |
Args:
|
| 645 |
workflow: workflow configuration
|
| 646 |
components: workflow components
|
|
|
|
| 647 |
"""
|
| 648 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 649 |
# Get workflow process
|
| 650 |
-
process = Process.get(components)
|
| 651 |
|
| 652 |
# Run workflow process
|
| 653 |
-
process.run(
|
| 654 |
|
| 655 |
# Run search
|
| 656 |
-
if
|
| 657 |
-
process.search(
|
| 658 |
-
else:
|
| 659 |
-
# Clear session query
|
| 660 |
-
st.session_state["query"] = None
|
| 661 |
|
| 662 |
def run(self):
|
| 663 |
"""
|
|
@@ -680,7 +687,7 @@ class Application:
|
|
| 680 |
|
| 681 |
if selected:
|
| 682 |
# Process current action
|
| 683 |
-
self.process(workflow, components)
|
| 684 |
|
| 685 |
with st.sidebar:
|
| 686 |
# Generate export button after workflow is complete
|
|
|
|
| 24 |
|
| 25 |
@staticmethod
|
| 26 |
@st.cache(ttl=30 * 60, max_entries=3, allow_output_mutation=True, show_spinner=False)
|
| 27 |
+
def get(components, data):
|
| 28 |
"""
|
| 29 |
Lookup or creates a new workflow process instance.
|
| 30 |
|
| 31 |
Args:
|
| 32 |
components: input components
|
| 33 |
+
data: initial data, only passed when indexing
|
| 34 |
|
| 35 |
Returns:
|
| 36 |
Process
|
| 37 |
"""
|
| 38 |
|
| 39 |
+
process = Process(data)
|
| 40 |
|
| 41 |
# Build workflow
|
| 42 |
with st.spinner("Building workflow...."):
|
|
|
|
| 44 |
|
| 45 |
return process
|
| 46 |
|
| 47 |
+
def __init__(self, data):
|
| 48 |
"""
|
| 49 |
Creates a new Process.
|
| 50 |
+
|
| 51 |
+
Args:
|
| 52 |
+
data: initial data, only passed when indexing
|
| 53 |
"""
|
| 54 |
|
| 55 |
# Component options
|
|
|
|
| 64 |
# Embeddings index params
|
| 65 |
self.embeddings = None
|
| 66 |
self.documents = None
|
| 67 |
+
self.data = data
|
| 68 |
|
| 69 |
def build(self, components):
|
| 70 |
"""
|
|
|
|
| 619 |
# Wrap data as list for workflow processing
|
| 620 |
return [data]
|
| 621 |
|
| 622 |
+
def query(self, workflow, index):
|
| 623 |
"""
|
| 624 |
Gets input query.
|
| 625 |
|
| 626 |
Args:
|
| 627 |
workflow: workflow configuration
|
| 628 |
+
index: True if this is an indexing workflow
|
| 629 |
|
| 630 |
Returns:
|
| 631 |
input query
|
|
|
|
| 634 |
default = self.appsetting(workflow, "query")
|
| 635 |
default = default if default else ""
|
| 636 |
|
| 637 |
+
# Get query if this is an indexing workflow
|
| 638 |
+
query = st.text_input("Query", value=default) if index else None
|
| 639 |
|
| 640 |
# Save query state
|
| 641 |
st.session_state["query"] = query
|
| 642 |
|
| 643 |
return query
|
| 644 |
|
| 645 |
+
def process(self, workflow, components, index):
|
| 646 |
"""
|
| 647 |
Processes the current application action.
|
| 648 |
|
| 649 |
Args:
|
| 650 |
workflow: workflow configuration
|
| 651 |
components: workflow components
|
| 652 |
+
index: True if this is an indexing workflow
|
| 653 |
"""
|
| 654 |
|
| 655 |
+
# Get input data and initialize query
|
| 656 |
+
data = self.data(workflow)
|
| 657 |
+
query = self.query(workflow, index)
|
| 658 |
+
|
| 659 |
# Get workflow process
|
| 660 |
+
process = Process.get(components, data if index else None)
|
| 661 |
|
| 662 |
# Run workflow process
|
| 663 |
+
process.run(data)
|
| 664 |
|
| 665 |
# Run search
|
| 666 |
+
if index:
|
| 667 |
+
process.search(query)
|
|
|
|
|
|
|
|
|
|
| 668 |
|
| 669 |
def run(self):
|
| 670 |
"""
|
|
|
|
| 687 |
|
| 688 |
if selected:
|
| 689 |
# Process current action
|
| 690 |
+
self.process(workflow, components, "embeddings" in selected)
|
| 691 |
|
| 692 |
with st.sidebar:
|
| 693 |
# Generate export button after workflow is complete
|