Spaces:
Sleeping
Sleeping
Add JSON modif on unparsed files
Browse files
app.py
CHANGED
@@ -1268,12 +1268,53 @@ def main():
|
|
1268 |
st.dataframe(filtered_data)
|
1269 |
except Exception as e:
|
1270 |
st.error(f"An error occurred while reading the file: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1271 |
|
1272 |
# Parsed data
|
1273 |
parsed_tickbox = st.checkbox('Parsed Data')
|
1274 |
if parsed_tickbox:
|
1275 |
-
|
1276 |
-
|
|
|
|
|
|
|
|
|
1277 |
col1, col2 = st.columns(2)
|
1278 |
st.dataframe(parsed_responses)
|
1279 |
with col1:
|
|
|
1268 |
st.dataframe(filtered_data)
|
1269 |
except Exception as e:
|
1270 |
st.error(f"An error occurred while reading the file: {e}")
|
1271 |
+
modify_json = st.checkbox('Custom JSON')
|
1272 |
+
API_KEY = st.text_input('OpenAI API Key', API_KEY, type='password', help="Enter your OpenAI API key")
|
1273 |
+
if not API_KEY:
|
1274 |
+
st.warning("Please enter your API key to proceed.")
|
1275 |
+
if modify_json:
|
1276 |
+
FORMAT_LONG = st.text_area('Custom JSON', FORMAT_LONG, height=500)
|
1277 |
+
|
1278 |
+
# If the DataFrame is successfully created, allow the user to select a column
|
1279 |
+
col_unparsed = st.selectbox("Select column corresponding to text", data.columns)
|
1280 |
+
|
1281 |
+
if st.button("Process Column"):
|
1282 |
+
selected_column_data = filtered_data[col_unparsed].tolist()
|
1283 |
+
st.write("Column Data:", selected_column_data)
|
1284 |
+
st.session_state.result = selected_column_data
|
1285 |
+
if 'parsed_responses' not in st.session_state: # Button to trigger parsing of descriptions
|
1286 |
+
with st.status(f"Parsing..", expanded=True) as status:
|
1287 |
+
try:
|
1288 |
+
st.write("Parsing descriptions...")
|
1289 |
+
parser = UAPParser(api_key=API_KEY, model='gpt-3.5-turbo-0125', col=st.session_state.result)
|
1290 |
+
#descriptions = unparsed['description'].tolist()
|
1291 |
+
descriptions = st.session_state.result
|
1292 |
+
format_long = FORMAT_LONG
|
1293 |
+
parser.process_descriptions(descriptions, format_long)
|
1294 |
+
parsed_responses = parser.parse_responses()
|
1295 |
+
try:
|
1296 |
+
responses_df = parser.responses_to_df('sightingDetails', parsed_responses)
|
1297 |
+
except Exception as e:
|
1298 |
+
status.update(label=f"Error parsing: {e}", state="error")
|
1299 |
+
responses_df = parser.responses_to_df(parsed_responses)
|
1300 |
+
st.dataframe(responses_df)
|
1301 |
+
st.session_state['parsed_responses'] = responses_df.copy()
|
1302 |
+
status.update(label="Parsing complete", expanded=False)
|
1303 |
+
except Exception as e:
|
1304 |
+
status.update(label=f"Parsing failed : {e}", state="error")
|
1305 |
+
else:
|
1306 |
+
# Prompt the user to upload a file if they haven't already
|
1307 |
+
st.warning("Please upload a file to proceed.")
|
1308 |
|
1309 |
# Parsed data
|
1310 |
parsed_tickbox = st.checkbox('Parsed Data')
|
1311 |
if parsed_tickbox:
|
1312 |
+
if responses_df:
|
1313 |
+
parsed_responses = filter_dataframe(responses_df)
|
1314 |
+
st.session_state['parsed_responses'] = parsed_responses
|
1315 |
+
else:
|
1316 |
+
parsed_responses = filter_dataframe(parsed)
|
1317 |
+
st.session_state['parsed_responses'] = parsed_responses
|
1318 |
col1, col2 = st.columns(2)
|
1319 |
st.dataframe(parsed_responses)
|
1320 |
with col1:
|