faizhalas commited on
Commit
e531e52
·
verified ·
1 Parent(s): 36fd1cb

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -0
app.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+
4
+ hide_streamlit_style = """
5
+ <style>
6
+ #MainMenu {visibility: hidden;}
7
+ footer {visibility: hidden;}
8
+ </style>
9
+ """
10
+ st.markdown(hide_streamlit_style, unsafe_allow_html=True)
11
+
12
+ st.set_page_config(
13
+ page_title="File Checker",
14
+ page_icon="🥥",
15
+ layout="wide"
16
+ )
17
+ st.title('🥥 File Checker')
18
+
19
+ st.subheader('Put your file here...')
20
+
21
+ def reset_data():
22
+ st.cache_data.clear()
23
+
24
+ #===check filetype===
25
+ @st.cache_data(ttl=3600)
26
+ def get_ext(extype):
27
+ extype = uploaded_file.name
28
+ return extype
29
+
30
+ #===upload===
31
+ @st.cache_data(ttl=3600)
32
+ def upload(extype):
33
+ keywords = pd.read_csv(uploaded_file)
34
+ return keywords
35
+
36
+ @st.cache_data(ttl=3600)
37
+ def conv_txt(extype):
38
+ col_dict = {'TI': 'Title',
39
+ 'SO': 'Source title',
40
+ 'DE': 'Author Keywords',
41
+ 'ID': 'Keywords Plus'}
42
+ keywords = pd.read_csv(uploaded_file, sep='\t', lineterminator='\r')
43
+ keywords.rename(columns=col_dict, inplace=True)
44
+ return keywords
45
+
46
+ #===read data===
47
+ uploaded_file = st.file_uploader("Choose your a file", type=['csv','txt'], on_change=reset_data)
48
+
49
+ if uploaded_file is not None:
50
+ extype = get_ext(uploaded_file)
51
+ if extype.endswith('.csv'):
52
+ data = upload(extype)
53
+
54
+ elif extype.endswith('.txt'):
55
+ data = conv_txt(extype)
56
+
57
+ edited_df = st.data_editor(data)