Download app.py from manika07/etds: direct link, hf CLI and curl.
- Browser
- Download file 2.96 kB
-
https://huggingface.co/spaces/manika07/etds/resolve/main/app.py
- Command line
-
hf download hf://spaces/manika07/etds/app.py
-
curl -L -o app.py https://huggingface.co/spaces/manika07/etds/resolve/main/app.py
2.96 kB
| import streamlit as st | |
| import pandas as pd | |
| import pickle | |
| import requests | |
| import base64 | |
| #===config=== | |
| st.set_page_config( | |
| page_title="ETDs Tagging", | |
| page_icon="", | |
| layout="wide" | |
| ) | |
| st.header("Tagging Categories") | |
| st.subheader('Put your file here...') | |
| #========unique id======== | |
| def create_list(): | |
| l = [1, 2, 3] | |
| return l | |
| l = create_list() | |
| first_list_value = l[0] | |
| l[0] = first_list_value + 1 | |
| uID = str(l[0]) | |
| def get_ext(uploaded_file): | |
| extype = uID+uploaded_file.name | |
| return extype | |
| # def read_model(local_path): | |
| # with open(local_path, "rb") as f: | |
| # svm_classifier = pickle.load(f) | |
| # return svm_classifier | |
| # def read_tf(local_path): | |
| # with open(local_path, "rb") as f: | |
| # preprocessing = pickle.load(f) | |
| # return preprocessing | |
| def read_model(url): | |
| response = requests.get(url) | |
| open("temp.pkl", "wb").write(response.content) | |
| with open("temp.pkl", "rb") as f: | |
| svm_classifier = pickle.load(f) | |
| return svm_classifier | |
| def read_tf(url): | |
| response = requests.get(url) | |
| open("temp.pkl", "wb").write(response.content) | |
| with open("temp.pkl", "rb") as f: | |
| preprocessing = pickle.load(f) | |
| return preprocessing | |
| svm_classifier = read_model("https://github.com/manika-lamba/ml/raw/main/category/model2.pkl") | |
| preprocessing = read_tf("https://github.com/manika-lamba/ml/raw/main/category/preprocessing.pkl") | |
| # Function to predict the category for a given abstract | |
| def predict_category(abstract): | |
| # Preprocess the abstract | |
| abstract_preprocessed = preprocessing.transform([abstract]) | |
| # Make prediction | |
| prediction = svm_classifier.predict(abstract_preprocessed) | |
| return prediction | |
| # Create sidebar | |
| #===upload file=== | |
| def upload(file): | |
| papers = pd.read_csv(uploaded_file) | |
| return papers | |
| def conv_txt(extype): | |
| papers = pd.read_csv(uploaded_file, sep='\t', lineterminator='\r') | |
| papers.rename(columns=col_dict, inplace=True) | |
| return papers | |
| # Read Data | |
| uploaded_file = st.file_uploader("Choose a file", type=['csv']) | |
| st.sidebar.header("Download Results") | |
| st.sidebar.text("Download the tagged results as a CSV file.") | |
| if uploaded_file is not None: | |
| df = pd.read_csv(uploaded_file, encoding='latin-1') | |
| st.dataframe(df) | |
| # Tag the "Abstract" column with the corresponding categories | |
| df['category'] = df['Abstract'].apply(lambda x: predict_category(x)[0]) | |
| st.dataframe(df) | |
| # Convert DataFrame to CSV and encode it properly | |
| csv = df.to_csv(index=False).encode('utf-8') | |
| b64 = base64.b64encode(csv).decode() # Decode the Base64 encoded bytes | |
| st.sidebar.download_button( | |
| label="Download CSV", | |
| data=base64.b64decode(b64), # Decode Base64 to bytes | |
| file_name="results.csv", | |
| mime="text/csv", | |
| key='download-csv' | |
| ) |