nlpblogs commited on
Commit
bb97597
·
verified ·
1 Parent(s): 2c27c42

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -27
app.py CHANGED
@@ -44,7 +44,7 @@ with st.sidebar:
44
  }
45
  """,
46
  ):
47
- st.button("ONE-DAY SUBSCRIPTION")
48
 
49
 
50
  expander = st.expander("**Important notes on the Table Question Answering (QA) App**")
@@ -53,32 +53,24 @@ with st.sidebar:
53
  **Supported File Formats**
54
  This app accepts files in .csv and .xlsx formats.
55
 
56
-
57
  **How to Use**
58
  Upload your file first. Then, type your question into the text area provided and click the 'Retrieve your answer' button.
59
 
60
-
61
  **Usage Limits**
62
- You can ask up to 30 questions per day. Once you reach this limit, you will need to wait until the daily automatic renewal to continue using the app. The app's daily renewal occurs automatically.
63
-
64
 
65
  **Subscription Management**
66
- This app uses a one-day subscription plan. To cancel your subscription, please visit your Account settings.
67
-
68
 
69
  **Authorization**
70
- For security purposes, your authorization access expires hourly. To restore access, click the "Request Authorization" button. A file must be uploaded before you can request authorization.
71
-
72
 
73
  **Customization**
74
  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.
75
 
76
-
77
  **File Handling and Errors**
78
- The app may display an error message if your file is corrupt, contains missing values, or has other errors.
79
- To get your file cleaned and pre-processed before using this QA app, please use our Text Preprocessing Service which can be found in the navigation menu of our website: https://nlpblogs.com/
80
-
81
- For any other errors or inquiries, please contact us at [email protected]
82
 
83
  ''')
84
 
@@ -87,27 +79,28 @@ with st.sidebar:
87
  if 'question_attempts' not in st.session_state:
88
  st.session_state['question_attempts'] = 0
89
 
90
- max_attempts = 3
91
 
92
  # upload file
93
  upload_file = st.file_uploader("Upload your file. Accepted file formats include: .csv, .xlsx", type=['csv', 'xlsx'])
94
- df = None
95
 
96
  if upload_file is not None:
97
  file_extension = upload_file.name.split('.')[-1].lower()
98
  if file_extension == 'csv':
99
  try:
100
- df = pd.read_csv(io.StringIO(upload_file.getvalue().decode("utf-8")))
101
  if df.isnull().values.any():
102
  st.error("Error: The CSV file contains missing values.")
103
  st.stop()
104
  else:
105
  new_columns = [f'column_{i+1}' for i in range(len(df.columns))]
106
  df.columns = new_columns
107
-
108
  st.dataframe(df, key="csv_dataframe")
 
109
  st.write("_number of rows_", df.shape[0])
110
  st.write("_number of columns_", df.shape[1])
 
111
  except pd.errors.ParserError:
112
  st.error("Error: The CSV file is not readable or is incorrectly formatted.")
113
  st.stop()
@@ -119,7 +112,8 @@ if upload_file is not None:
119
  st.stop()
120
  elif file_extension == 'xlsx':
121
  try:
122
- df = pd.read_excel(io.BytesIO(upload_file.getvalue()))
 
123
  if df.isnull().values.any():
124
  st.error("Error: The Excel file contains missing values.")
125
  st.stop()
@@ -129,6 +123,7 @@ if upload_file is not None:
129
  st.dataframe(df, key="excel_dataframe")
130
  st.write("_number of rows_", df.shape[0])
131
  st.write("_number of columns_", df.shape[1])
 
132
  except ValueError:
133
  st.error("Error: The Excel file is not readable or is incorrectly formatted.")
134
  st.stop()
@@ -141,19 +136,23 @@ if upload_file is not None:
141
 
142
  # generate and validate Fernet token for the current file
143
  if 'fernet_token' not in st.session_state:
144
- if df is not None:
 
 
145
  st.session_state.fernet_token = generate_fernet_token(key, df.to_json())
146
  else:
147
  st.stop()
148
 
149
- decrypted_data_streamlit, error_streamlit = validate_fernet_token(key, st.session_state.fernet_token, ttl_seconds=10)
150
 
151
  if error_streamlit:
152
  st.warning("Please press Request Authorization. Please note that a file should be uploaded before you press Request Authorization.")
153
  if st.button("Request Authorization"):
154
- st.session_state.fernet_token = generate_fernet_token(key, df.to_json())
155
- st.success("Authorization granted")
156
- decrypted_data_streamlit, error_streamlit = validate_fernet_token(key, st.session_state.fernet_token, ttl_seconds=10)
 
 
157
  if error_streamlit:
158
  st.error(f"Your authorization has expired: {error_streamlit}")
159
  st.stop()
@@ -182,7 +181,7 @@ st.button("Clear question", on_click=clear_question)
182
  #retrive answer
183
  if st.button("Retrieve your answer"):
184
  if st.session_state['question_attempts'] >= max_attempts:
185
- st.error(f"You have asked {max_attempts} questions. You have reached your daily request limit. Your subscription will renew automatically. To cancel, please go to your Account.")
186
  st.stop()
187
  st.session_state['question_attempts'] += 1
188
  if error_streamlit:
@@ -191,8 +190,8 @@ if st.button("Retrieve your answer"):
191
  with st.spinner('Wait for it...'):
192
  time.sleep(2)
193
  if df is not None:
194
- tqa = pipeline(task="table-question-answering", model="google/tapas-base-finetuned-wikisql-supervised")
195
  st.write(tqa(table=df, query=question)['answer'])
196
 
197
  st.divider()
198
- st.write(f"Number of questions asked: {st.session_state['question_attempts']}/{max_attempts}")
 
44
  }
45
  """,
46
  ):
47
+ st.button("DEMO APP")
48
 
49
 
50
  expander = st.expander("**Important notes on the Table Question Answering (QA) App**")
 
53
  **Supported File Formats**
54
  This app accepts files in .csv and .xlsx formats.
55
 
 
56
  **How to Use**
57
  Upload your file first. Then, type your question into the text area provided and click the 'Retrieve your answer' button.
58
 
 
59
  **Usage Limits**
60
+ You can ask up to 5 questions.
 
61
 
62
  **Subscription Management**
63
+ This demo app offers 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 info@nlpblogs.com
 
64
 
65
  **Authorization**
66
+ For security purposes, your authorization access expires hourly. To restore access, click the 'Request Authorization' button.
 
67
 
68
  **Customization**
69
  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.
70
 
 
71
  **File Handling and Errors**
72
+ The app may display an error message if your file has errors or date values.
73
+ For any errors or inquiries, please contact us at info@nlpblogs.com
 
 
74
 
75
  ''')
76
 
 
79
  if 'question_attempts' not in st.session_state:
80
  st.session_state['question_attempts'] = 0
81
 
82
+ max_attempts = 5
83
 
84
  # upload file
85
  upload_file = st.file_uploader("Upload your file. Accepted file formats include: .csv, .xlsx", type=['csv', 'xlsx'])
86
+
87
 
88
  if upload_file is not None:
89
  file_extension = upload_file.name.split('.')[-1].lower()
90
  if file_extension == 'csv':
91
  try:
92
+ df = pd.read_csv(upload_file, na_filter=False)
93
  if df.isnull().values.any():
94
  st.error("Error: The CSV file contains missing values.")
95
  st.stop()
96
  else:
97
  new_columns = [f'column_{i+1}' for i in range(len(df.columns))]
98
  df.columns = new_columns
 
99
  st.dataframe(df, key="csv_dataframe")
100
+
101
  st.write("_number of rows_", df.shape[0])
102
  st.write("_number of columns_", df.shape[1])
103
+ st.session_state.df = df
104
  except pd.errors.ParserError:
105
  st.error("Error: The CSV file is not readable or is incorrectly formatted.")
106
  st.stop()
 
112
  st.stop()
113
  elif file_extension == 'xlsx':
114
  try:
115
+ df = pd.read_excel(upload_file, na_filter=False)
116
+
117
  if df.isnull().values.any():
118
  st.error("Error: The Excel file contains missing values.")
119
  st.stop()
 
123
  st.dataframe(df, key="excel_dataframe")
124
  st.write("_number of rows_", df.shape[0])
125
  st.write("_number of columns_", df.shape[1])
126
+ st.session_state.df = df
127
  except ValueError:
128
  st.error("Error: The Excel file is not readable or is incorrectly formatted.")
129
  st.stop()
 
136
 
137
  # generate and validate Fernet token for the current file
138
  if 'fernet_token' not in st.session_state:
139
+ if 'df' in st.session_state:
140
+ df = st.session_state.df
141
+
142
  st.session_state.fernet_token = generate_fernet_token(key, df.to_json())
143
  else:
144
  st.stop()
145
 
146
+ decrypted_data_streamlit, error_streamlit = validate_fernet_token(key, st.session_state.fernet_token, ttl_seconds=3600)
147
 
148
  if error_streamlit:
149
  st.warning("Please press Request Authorization. Please note that a file should be uploaded before you press Request Authorization.")
150
  if st.button("Request Authorization"):
151
+ if 'df' in st.session_state:
152
+ df = st.session_state.df
153
+ st.session_state.fernet_token = generate_fernet_token(key, df.to_json())
154
+ st.success("Authorization granted")
155
+ decrypted_data_streamlit, error_streamlit = validate_fernet_token(key, st.session_state.fernet_token, ttl_seconds=3600)
156
  if error_streamlit:
157
  st.error(f"Your authorization has expired: {error_streamlit}")
158
  st.stop()
 
181
  #retrive answer
182
  if st.button("Retrieve your answer"):
183
  if st.session_state['question_attempts'] >= max_attempts:
184
+ st.error(f"You have asked {max_attempts} questions. Maximum question attempts reached.")
185
  st.stop()
186
  st.session_state['question_attempts'] += 1
187
  if error_streamlit:
 
190
  with st.spinner('Wait for it...'):
191
  time.sleep(2)
192
  if df is not None:
193
+ tqa = pipeline(task="table-question-answering", model="microsoft/tapex-large-finetuned-wtq")
194
  st.write(tqa(table=df, query=question)['answer'])
195
 
196
  st.divider()
197
+ st.write(f"Number of questions asked: {st.session_state['question_attempts']}/{max_attempts}")