Update app.py
Browse files
app.py
CHANGED
@@ -49,48 +49,58 @@ id2label = {
|
|
49 |
# Source: https://blog.jcharistech.com/2021/01/21/how-to-save-uploaded-files-to-directory-in-streamlit-apps/
|
50 |
|
51 |
# Store uploaded file temporarily in directory to get file path (necessary for processing)
|
52 |
-
def save_uploadedfile(upl_file):
|
53 |
-
|
54 |
-
|
55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
|
57 |
if uploaded_file is not None:
|
58 |
-
# Save the file
|
59 |
-
file_details = {"FileName": uploaded_file.name, "FileType": uploaded_file.type}
|
60 |
-
save_uploadedfile(uploaded_file)
|
61 |
|
62 |
-
#
|
63 |
-
|
|
|
|
|
|
|
64 |
|
65 |
-
|
|
|
66 |
|
67 |
-
### Make predictions
|
68 |
-
preds = vg_model(par_list)
|
69 |
|
70 |
-
# Get label names
|
71 |
-
preds_list = preds.tolist()
|
72 |
|
73 |
-
predictions_names=[]
|
74 |
|
75 |
-
# loop through each prediction
|
76 |
-
for ele in preds_list:
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
|
87 |
-
# Combine the paragraphs and labels to a dataframe
|
88 |
-
df_predictions = pd.DataFrame({'Paragraph': par_list, 'Prediction': predictions_names})
|
89 |
|
90 |
-
# Drop all "Other" and "NA" predictions
|
91 |
-
filtered_df = df[df['Prediction'].isin(['Other', 'NA'])]
|
92 |
|
93 |
|
94 |
-
#####################################
|
95 |
-
st.write(df)
|
96 |
|
|
|
49 |
# Source: https://blog.jcharistech.com/2021/01/21/how-to-save-uploaded-files-to-directory-in-streamlit-apps/
|
50 |
|
51 |
# Store uploaded file temporarily in directory to get file path (necessary for processing)
|
52 |
+
# def save_uploadedfile(upl_file):
|
53 |
+
# with open(os.path.join("tempDir",upl_file.name),"wb") as f:
|
54 |
+
# f.write(upl_file.getbuffer())
|
55 |
+
# return st.success("Saved File:{} to tempDir".format(upl_file.name))
|
56 |
+
|
57 |
+
# if uploaded_file is not None:
|
58 |
+
# # Save the file
|
59 |
+
# file_details = {"FileName": uploaded_file.name, "FileType": uploaded_file.type}
|
60 |
+
# save_uploadedfile(uploaded_file)
|
61 |
+
|
62 |
+
# #Get the file path
|
63 |
+
|
64 |
+
file = st.file_uploader("File upload", type=["pdf"])
|
65 |
|
66 |
if uploaded_file is not None:
|
|
|
|
|
|
|
67 |
|
68 |
+
# Retrieve the file name
|
69 |
+
with tempfile.NamedTemporaryFile(mode="wb") as temp:
|
70 |
+
bytes_data = files.getvalue()
|
71 |
+
temp.write(bytes_data)
|
72 |
+
print(temp.name)
|
73 |
|
74 |
+
# # Process file
|
75 |
+
# par_list = get_paragraphs(uploaded_file)
|
76 |
|
77 |
+
# ### Make predictions
|
78 |
+
# preds = vg_model(par_list)
|
79 |
|
80 |
+
# # Get label names
|
81 |
+
# preds_list = preds.tolist()
|
82 |
|
83 |
+
# predictions_names=[]
|
84 |
|
85 |
+
# # loop through each prediction
|
86 |
+
# for ele in preds_list:
|
87 |
+
# try:
|
88 |
+
# index_of_one = ele.index(1)
|
89 |
+
# except ValueError:
|
90 |
+
# index_of_one = "NA"
|
91 |
+
# if index_of_one != "NA":
|
92 |
+
# name = id2label[index_of_one]
|
93 |
+
# else:
|
94 |
+
# name = "NA"
|
95 |
+
# predictions_names.append(name)
|
96 |
|
97 |
+
# # Combine the paragraphs and labels to a dataframe
|
98 |
+
# df_predictions = pd.DataFrame({'Paragraph': par_list, 'Prediction': predictions_names})
|
99 |
|
100 |
+
# # Drop all "Other" and "NA" predictions
|
101 |
+
# filtered_df = df[df['Prediction'].isin(['Other', 'NA'])]
|
102 |
|
103 |
|
104 |
+
# #####################################
|
105 |
+
# st.write(df)
|
106 |
|