manika07 commited on
Commit
4666190
Β·
1 Parent(s): 315df7d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -21
app.py CHANGED
@@ -25,13 +25,7 @@ def read_tf(url):
25
  svm_classifier = read_model("https://github.com/manika-lamba/ml/raw/main/model2.pkl")
26
  preprocessing = read_tf("https://github.com/manika-lamba/ml/raw/main/preprocessing.pkl")
27
 
28
- # Function to predict the category for a given abstract
29
- def predict_category(abstract):
30
- # Preprocess the abstract
31
- abstract_preprocessed = preprocessing.transform([abstract])
32
- # Make prediction
33
- prediction = svm_classifier.predict(abstract_preprocessed)
34
- return prediction
35
 
36
  # Create sidebar
37
 
@@ -39,22 +33,40 @@ def predict_category(abstract):
39
  st.sidebar.header("Choose CSV File with 'Abstract' field")
40
  uploaded_file = st.sidebar.file_uploader("", type=["csv"])
41
 
42
- if uploaded_file is not None:
43
- df = pd.read_csv(uploaded_file, encoding='latin-1')
44
- st.dataframe(df)
45
- # Tag the "Abstract" column with the corresponding categories
46
- df['category'] = df['Abstract'].apply(predict_category)
47
- st.dataframe(df)
48
-
49
  st.sidebar.header("Download Results")
50
  st.sidebar.text("Download the tagged results as a CSV file.")
51
 
52
- # Create a download button
53
- if st.sidebar.button("Download"):
54
- csv = df.to_csv(index=False)
55
- b64 = base64.b64encode(csv.encode()).decode()
56
- href = f'<a href="data:file/csv;base64,{b64}" download="results.csv">Download csv file</a>'
57
- st.markdown(href, unsafe_allow_html=True)
58
 
59
  st.title("About")
60
- st.subheader("")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  svm_classifier = read_model("https://github.com/manika-lamba/ml/raw/main/model2.pkl")
26
  preprocessing = read_tf("https://github.com/manika-lamba/ml/raw/main/preprocessing.pkl")
27
 
28
+
 
 
 
 
 
 
29
 
30
  # Create sidebar
31
 
 
33
  st.sidebar.header("Choose CSV File with 'Abstract' field")
34
  uploaded_file = st.sidebar.file_uploader("", type=["csv"])
35
 
 
 
 
 
 
 
 
36
  st.sidebar.header("Download Results")
37
  st.sidebar.text("Download the tagged results as a CSV file.")
38
 
39
+
 
 
 
 
 
40
 
41
  st.title("About")
42
+ st.subheader("You can tag your input CSV file of theses and dissertations with Library Science, Archival Studies, and Information Science categories. The screen will show the output.")
43
+
44
+ tab1, tab2, tab3 = st.tabs(["πŸ“ˆ Load Data", "πŸ“ƒ Tagged ETDs", "πŸ““ Download Data"])
45
+ with tab1:
46
+ #===load data===
47
+ if uploaded_file is not None:
48
+ df = pd.read_csv(uploaded_file, encoding='latin-1')
49
+ st.dataframe(df)
50
+
51
+
52
+ with tab2:
53
+ #===tagged ETDs===
54
+ # Tag the "Abstract" column with the corresponding categories
55
+ df['category'] = df['Abstract'].apply(predict_category)
56
+ st.dataframe(df)
57
+ # Function to predict the category for a given abstract
58
+ def predict_category(abstract):
59
+ # Preprocess the abstract
60
+ abstract_preprocessed = preprocessing.transform([abstract])
61
+ # Make prediction
62
+ prediction = svm_classifier.predict(abstract_preprocessed)
63
+ return prediction
64
+
65
+ with tab3:
66
+ #===download result===
67
+ # Create a download button
68
+ if st.sidebar.button("Download"):
69
+ csv = df.to_csv(index=False)
70
+ b64 = base64.b64encode(csv.encode()).decode()
71
+ href = f'<a href="data:file/csv;base64,{b64}" download="results.csv">Download csv file</a>'
72
+ st.markdown(href, unsafe_allow_html=True)