Spaces:
Sleeping
Sleeping
pj2111
commited on
Commit
Β·
9301e19
1
Parent(s):
02a6902
app modified to pages
Browse files- .DS_Store +0 -0
- Hello.py +18 -0
- capture.png +0 -0
- app.py β pages/1_Classification.py +0 -0
- pages/2_Batch_classification.py +38 -0
.DS_Store
CHANGED
Binary files a/.DS_Store and b/.DS_Store differ
|
|
Hello.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
st.set_page_config(
|
4 |
+
page_title="Zero-Shot Classification",
|
5 |
+
page_icon="π",
|
6 |
+
)
|
7 |
+
|
8 |
+
st.write("# Welcome to Zero-Shot Classification! π")
|
9 |
+
|
10 |
+
st.sidebar.success("Select a demo above.")
|
11 |
+
|
12 |
+
st.markdown(
|
13 |
+
"""
|
14 |
+
Zero-shot text classification is a task in natural language processing where a model is trained on a
|
15 |
+
set of labeled examples but is then able to classify new examples from previously unseen classes.
|
16 |
+
"""
|
17 |
+
)
|
18 |
+
st.image('capture.png')
|
capture.png
ADDED
![]() |
app.py β pages/1_Classification.py
RENAMED
File without changes
|
pages/2_Batch_classification.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
import streamlit as st
|
3 |
+
from transformers import pipeline
|
4 |
+
|
5 |
+
st.title("Zeroshot Classification - Batched")
|
6 |
+
st.caption("A streamlit powered app")
|
7 |
+
|
8 |
+
uploaded_file = st.file_uploader("Upload your file here")
|
9 |
+
if uploaded_file is not None:
|
10 |
+
# Can be used wherever a "file-like" object is accepted:
|
11 |
+
df = pd.read_excel(uploaded_file)
|
12 |
+
st.write(df)
|
13 |
+
col_name = st.text_input("Which column contains text that you want to classify")
|
14 |
+
|
15 |
+
classes = st.text_input("Enter possible class names (comma-separated)")
|
16 |
+
|
17 |
+
pipe = pipeline('zero-shot-classification','facebook/bart-large-mnli')
|
18 |
+
batch_output = pipe(list(df[col_name]),classes)
|
19 |
+
df['predicted']=[i['labels'][0] for i in batch_output]
|
20 |
+
|
21 |
+
st.write(df)
|
22 |
+
|
23 |
+
@st.cache_data
|
24 |
+
def convert_df(df):
|
25 |
+
# IMPORTANT: Cache the conversion to prevent computation on every rerun
|
26 |
+
return df.to_csv().encode("utf-8")
|
27 |
+
|
28 |
+
csv = convert_df(df)
|
29 |
+
|
30 |
+
st.download_button(
|
31 |
+
label="Download data as CSV",
|
32 |
+
data=csv,
|
33 |
+
file_name="large_df.csv",
|
34 |
+
mime="text/csv",
|
35 |
+
)
|
36 |
+
# with st.form('upload-form', clear_on_submit=True):
|
37 |
+
# uploaded_file = st.file_uploader("Upload your file here")
|
38 |
+
# submitted = st.form_submit_button("Upload")
|