-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
134 lines (116 loc) · 4.52 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import streamlit as st
from builder.pipeline_builder import PipelineBuilder
from utils.textextractor import Utils # Import Utils
# Initialize the PipelineBuilder
builder = PipelineBuilder()
# Task Classification Function
def classify_task(user_input):
user_input = user_input.lower()
if "summarize" in user_input or "summary" in user_input:
return "Summarize"
elif "what" in user_input or "explain" in user_input or "insight" in user_input:
return "Answer Query"
elif "translate" in user_input:
return "Translate"
elif "extract" in user_input:
return "Extract Information"
elif "generate" in user_input or "create" in user_input:
return "Generate Content"
else:
return "Unknown Task"
# Step 1: Ask the user for their query
st.title("Bel Esprit Framework")
st.subheader("Step 1: What do you want to do?")
user_input = st.text_area("Enter your task or query:", placeholder="E.g., Summarize the key points of this document.")
# Initialize variables
task_type = None
input_language = None
text_content = None
output_format = None
output_language = None
# Step 2: Automatically classify the task
if user_input:
task_type = classify_task(user_input)
st.subheader("Detected Task")
st.write(f"The system has classified your task as: **{task_type}**")
else:
task_type = None
# Step 3: Ask for the language of the input
if task_type:
st.subheader("Step 2: What is the language of your input?")
input_language = st.text_input(
"Enter the language of the input text (e.g., English, Spanish, etc.):",
placeholder="E.g., English"
)
output_language = input_language
if task_type == "Translate":
st.subheader("Step 2: What is the language of your output?")
output_language = st.text_input(
"Enter the language of the output text (e.g., English, Spanish, etc.):",
placeholder="E.g., French"
)
have_document = "No"
# Step 4: Provide the text content
if input_language:
st.subheader("Step 3: Do you have a document to process?")
have_document = st.selectbox(
"Select an option",
options=["No", "Yes"],
index=0
)
st.subheader("Step 4: Define the Output Format")
output_format = "Answer" if task_type == "Answer Query" else task_type
st.write(f"Based on your task, the output format will be: **{output_format}**.")
# Step 6: Build the pipeline
if st.button("Build Pipeline"):
if task_type and input_language and output_format:
# Define specifications
if have_document == "Yes":
specifications = {
"inputs": [
{
"name": "Text Content",
"type": "file",
"language": input_language,
"content": "file_content"
}
],
"task": task_type,
"outputs": [
{
"name": "Result",
"type": output_format.lower(),
"language": input_language
}
]
}
else:
specifications = {
"inputs": [
{
"name": "Text Content",
"type": "text",
"language": input_language,
"content": "user_input"
}
],
"task": task_type,
"outputs": [
{
"name": "Result",
"type": output_format.lower(),
"language": output_language
}
]
}
# Generate the pipeline
full_pipeline = builder.generate_pipeline(
user_query=user_input,
refined_query=f"For the given {task_type.lower()} on the given {specifications} create the pipeline.",
specifications=specifications
)
st.subheader("Generated Pipeline")
st.json(full_pipeline)
st.success("Pipeline built successfully! You can now execute the pipeline.")
else:
st.error("Please complete all fields before building the pipeline.")