Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -7,62 +7,48 @@ from streamlit_extras.stylable_container import stylable_container
|
|
7 |
import json
|
8 |
import plotly.express as px
|
9 |
|
10 |
-
st.subheader("
|
|
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
# sidebar
|
16 |
-
with st.sidebar:
|
17 |
-
with stylable_container(
|
18 |
-
key="test_button",
|
19 |
-
css_styles="""
|
20 |
-
button {
|
21 |
-
background-color: yellow;
|
22 |
-
border: 1px solid black;
|
23 |
-
padding: 5px;
|
24 |
-
color: black;
|
25 |
-
}
|
26 |
-
""",
|
27 |
-
):
|
28 |
-
st.button("DEMO APP")
|
29 |
-
|
30 |
-
|
31 |
-
expander = st.expander("**Important notes on the Table Question Answering (QA) App**")
|
32 |
-
expander.write('''
|
33 |
|
34 |
**Supported File Formats**
|
35 |
This app accepts files in .csv and .xlsx formats.
|
36 |
|
37 |
**How to Use**
|
38 |
-
Upload your file first. Then, type your question into the text area provided and click the 'Retrieve your answer' button.
|
39 |
|
40 |
**Usage Limits**
|
41 |
You can ask up to 5 questions.
|
42 |
|
43 |
**Subscription Management**
|
44 |
-
This
|
45 |
-
|
46 |
-
**Authorization**
|
47 |
-
For security purposes, your authorization access expires hourly. To restore access, click the 'Request Authorization' button.
|
48 |
|
49 |
**Customization**
|
50 |
To change the app's background color to white or black, click the three-dot menu on the right-hand side of your app, go to Settings and then Choose app theme, colors and fonts.
|
51 |
|
52 |
**File Handling and Errors**
|
53 |
The app may display an error message if your file has errors or date values.
|
|
|
54 |
For any errors or inquiries, please contact us at [email protected]
|
55 |
|
56 |
''')
|
57 |
-
|
58 |
-
|
59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
if 'question_attempts' not in st.session_state:
|
61 |
st.session_state['question_attempts'] = 0
|
62 |
|
63 |
max_attempts = 5
|
64 |
|
65 |
-
|
66 |
upload_file = st.file_uploader("Upload your file. Accepted file formats include: .csv, .xlsx", type=['csv', 'xlsx'])
|
67 |
|
68 |
|
@@ -78,6 +64,8 @@ if upload_file is not None:
|
|
78 |
new_columns = [f'column_{i+1}' for i in range(len(df.columns))]
|
79 |
df.columns = new_columns
|
80 |
st.dataframe(df, key="csv_dataframe")
|
|
|
|
|
81 |
all_columns = df.columns.tolist()
|
82 |
st.subheader("Select columns for the Tree Map", divider="blue")
|
83 |
parent_column = st.selectbox("Select the parent column:", all_columns)
|
@@ -85,7 +73,7 @@ if upload_file is not None:
|
|
85 |
|
86 |
if parent_column and value_column:
|
87 |
if parent_column == value_column:
|
88 |
-
st.warning("Warning: You have selected the same column for both the parent and value. This might not produce a meaningful treemap.")
|
89 |
elif parent_column and value_column:
|
90 |
path_columns = [px.Constant("all"), parent_column, value_column]
|
91 |
fig = px.treemap(df,
|
@@ -95,8 +83,7 @@ if upload_file is not None:
|
|
95 |
st.subheader("Tree map", divider="red")
|
96 |
st.plotly_chart(fig)
|
97 |
|
98 |
-
|
99 |
-
st.write("_number of columns_", df.shape[1])
|
100 |
st.session_state.df = df
|
101 |
except pd.errors.ParserError:
|
102 |
st.error("Error: The CSV file is not readable or is incorrectly formatted.")
|
@@ -117,13 +104,29 @@ if upload_file is not None:
|
|
117 |
else:
|
118 |
new_columns = [f'column_{i+1}' for i in range(len(df.columns))]
|
119 |
df.columns = new_columns
|
120 |
-
st.
|
121 |
-
st.dataframe(df, key="excel_dataframe")
|
122 |
-
|
123 |
-
|
124 |
st.write("_number of rows_", df.shape[0])
|
125 |
st.write("_number of columns_", df.shape[1])
|
126 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
127 |
except ValueError:
|
128 |
st.error("Error: The Excel file is not readable or is incorrectly formatted.")
|
129 |
st.stop()
|
@@ -138,17 +141,16 @@ if upload_file is not None:
|
|
138 |
|
139 |
|
140 |
|
141 |
-
|
142 |
st.divider()
|
143 |
|
144 |
-
|
145 |
def clear_question():
|
146 |
st.session_state["question"] = ""
|
147 |
|
148 |
question = st.text_input("Type your question here and then press **Retrieve your answer**:", key="question")
|
149 |
st.button("Clear question", on_click=clear_question)
|
150 |
|
151 |
-
|
152 |
if st.button("Retrieve your answer"):
|
153 |
if st.session_state['question_attempts'] >= max_attempts:
|
154 |
st.error(f"You have asked {max_attempts} questions. Maximum question attempts reached.")
|
@@ -157,8 +159,8 @@ if st.button("Retrieve your answer"):
|
|
157 |
if error_streamlit:
|
158 |
st.warning("Please enter a question before retrieving the answer.")
|
159 |
else:
|
160 |
-
with st.spinner(
|
161 |
-
time.sleep(
|
162 |
if df is not None:
|
163 |
tqa = pipeline(task="table-question-answering", model="microsoft/tapex-large-finetuned-wtq")
|
164 |
st.write(tqa(table=df, query=question)['answer'])
|
|
|
7 |
import json
|
8 |
import plotly.express as px
|
9 |
|
10 |
+
st.subheader("AI CSV and XLSX Data Analyzer", divider="blue")
|
11 |
+
st.link_button("by nlpblogs", "https://nlpblogs.com", type = "tertiary")
|
12 |
|
13 |
+
expander = st.expander("**Important notes on the AI CSV and XLSX Data Analyzer**")
|
14 |
+
expander.write('''
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
**Supported File Formats**
|
17 |
This app accepts files in .csv and .xlsx formats.
|
18 |
|
19 |
**How to Use**
|
20 |
+
Upload your file first. Select two different columns from your data to visualize in a tree map. Then, type your question into the text area provided and click the 'Retrieve your answer' button.
|
21 |
|
22 |
**Usage Limits**
|
23 |
You can ask up to 5 questions.
|
24 |
|
25 |
**Subscription Management**
|
26 |
+
This app offers a one-day free trial, followed by a one-day subscription, expiring after 24 hours. If you are interested in building your own Table Question Answering (QA) Web App, we invite you to explore our NLP Web App Store on our website. You can select your desired features, place your order, and we will deliver your custom app in five business days. If you wish to delete your Account with us, please contact us at [email protected]
|
|
|
|
|
|
|
27 |
|
28 |
**Customization**
|
29 |
To change the app's background color to white or black, click the three-dot menu on the right-hand side of your app, go to Settings and then Choose app theme, colors and fonts.
|
30 |
|
31 |
**File Handling and Errors**
|
32 |
The app may display an error message if your file has errors or date values.
|
33 |
+
|
34 |
For any errors or inquiries, please contact us at [email protected]
|
35 |
|
36 |
''')
|
37 |
+
|
38 |
+
|
39 |
+
with st.sidebar:
|
40 |
+
container = st.container(border=True)
|
41 |
+
container.write("**Question-Answering (QA)** is the task of retrieving the answer to a question from a given text (knowledge base), which is used as context.")
|
42 |
+
st.subheader("Related NLP Web Apps", divider = "blue")
|
43 |
+
st.link_button("14-Named Entity Recognition Web App", "https://nlpblogs.com/shop/table-question-answering-qa/google-sheet-qa-demo-app/", type = "primary")
|
44 |
+
|
45 |
+
|
46 |
if 'question_attempts' not in st.session_state:
|
47 |
st.session_state['question_attempts'] = 0
|
48 |
|
49 |
max_attempts = 5
|
50 |
|
51 |
+
|
52 |
upload_file = st.file_uploader("Upload your file. Accepted file formats include: .csv, .xlsx", type=['csv', 'xlsx'])
|
53 |
|
54 |
|
|
|
64 |
new_columns = [f'column_{i+1}' for i in range(len(df.columns))]
|
65 |
df.columns = new_columns
|
66 |
st.dataframe(df, key="csv_dataframe")
|
67 |
+
st.write("_number of rows_", df.shape[0])
|
68 |
+
st.write("_number of columns_", df.shape[1])
|
69 |
all_columns = df.columns.tolist()
|
70 |
st.subheader("Select columns for the Tree Map", divider="blue")
|
71 |
parent_column = st.selectbox("Select the parent column:", all_columns)
|
|
|
73 |
|
74 |
if parent_column and value_column:
|
75 |
if parent_column == value_column:
|
76 |
+
st.warning("Warning: You have selected the same column for both the parent and value column. Please select two different columns from your data.This might not produce a meaningful treemap.")
|
77 |
elif parent_column and value_column:
|
78 |
path_columns = [px.Constant("all"), parent_column, value_column]
|
79 |
fig = px.treemap(df,
|
|
|
83 |
st.subheader("Tree map", divider="red")
|
84 |
st.plotly_chart(fig)
|
85 |
|
86 |
+
|
|
|
87 |
st.session_state.df = df
|
88 |
except pd.errors.ParserError:
|
89 |
st.error("Error: The CSV file is not readable or is incorrectly formatted.")
|
|
|
104 |
else:
|
105 |
new_columns = [f'column_{i+1}' for i in range(len(df.columns))]
|
106 |
df.columns = new_columns
|
107 |
+
st.dataframe(df, key="csv_dataframe")
|
|
|
|
|
|
|
108 |
st.write("_number of rows_", df.shape[0])
|
109 |
st.write("_number of columns_", df.shape[1])
|
110 |
+
all_columns = df.columns.tolist()
|
111 |
+
st.subheader("Select columns for the Tree Map", divider="blue")
|
112 |
+
parent_column = st.selectbox("Select the parent column:", all_columns)
|
113 |
+
value_column = st.selectbox("Select the value column:", all_columns)
|
114 |
+
|
115 |
+
if parent_column and value_column:
|
116 |
+
if parent_column == value_column:
|
117 |
+
st.warning("Warning: You have selected the same column for both the parent and value column. Please select two different columns from your data.This might not produce a meaningful treemap.")
|
118 |
+
elif parent_column and value_column:
|
119 |
+
path_columns = [px.Constant("all"), parent_column, value_column]
|
120 |
+
fig = px.treemap(df,
|
121 |
+
path=path_columns)
|
122 |
+
|
123 |
+
fig.update_layout(margin=dict(t=50, l=25, r=25, b=25))
|
124 |
+
st.subheader("Tree map", divider="red")
|
125 |
+
st.plotly_chart(fig)
|
126 |
+
|
127 |
+
|
128 |
+
st.session_state.df = df
|
129 |
+
|
130 |
except ValueError:
|
131 |
st.error("Error: The Excel file is not readable or is incorrectly formatted.")
|
132 |
st.stop()
|
|
|
141 |
|
142 |
|
143 |
|
|
|
144 |
st.divider()
|
145 |
|
146 |
+
|
147 |
def clear_question():
|
148 |
st.session_state["question"] = ""
|
149 |
|
150 |
question = st.text_input("Type your question here and then press **Retrieve your answer**:", key="question")
|
151 |
st.button("Clear question", on_click=clear_question)
|
152 |
|
153 |
+
|
154 |
if st.button("Retrieve your answer"):
|
155 |
if st.session_state['question_attempts'] >= max_attempts:
|
156 |
st.error(f"You have asked {max_attempts} questions. Maximum question attempts reached.")
|
|
|
159 |
if error_streamlit:
|
160 |
st.warning("Please enter a question before retrieving the answer.")
|
161 |
else:
|
162 |
+
with st.spinner("Wait for it...", show_time=True):
|
163 |
+
time.sleep(5)
|
164 |
if df is not None:
|
165 |
tqa = pipeline(task="table-question-answering", model="microsoft/tapex-large-finetuned-wtq")
|
166 |
st.write(tqa(table=df, query=question)['answer'])
|