Spaces:
Runtime error
Runtime error
Support for files added
Browse files
app.py
CHANGED
@@ -15,7 +15,7 @@ from check import is_str_in
|
|
15 |
import streamlit as st
|
16 |
|
17 |
st.title("Expense Tagging")
|
18 |
-
st.subheader("
|
19 |
|
20 |
file_name = "brands.json"
|
21 |
with open(file_name,'r') as f:
|
@@ -42,29 +42,59 @@ with open('tfidf2.pickle','rb') as to_read:
|
|
42 |
|
43 |
map_dict = {0:"Food and Groceries", 1:"Medical and Healthcare",2:"Education",3:"Lifestyle and Entertainment",4:"Travel & Transportation",5:"Clothing"}
|
44 |
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
if submit:
|
50 |
-
st.subheader("Output Text")
|
51 |
-
with st.spinner(text="This may take a moment..."):
|
52 |
-
time.sleep(2)
|
53 |
-
bo,ind = is_str_in(brand,brands)
|
54 |
-
if bo:
|
55 |
-
out = categories[ind]
|
56 |
|
57 |
-
|
58 |
-
|
59 |
-
w = fitted_tfidf.transform([brand])
|
60 |
# print(w)
|
61 |
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
# print(loaded_model.predict(w))
|
66 |
#out = categories[out]
|
67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
|
69 |
#'''
|
70 |
|
|
|
15 |
import streamlit as st
|
16 |
|
17 |
st.title("Expense Tagging")
|
18 |
+
st.subheader("Upload a txt file with each line containing a brand, we'll tell you their categories")
|
19 |
|
20 |
file_name = "brands.json"
|
21 |
with open(file_name,'r') as f:
|
|
|
42 |
|
43 |
map_dict = {0:"Food and Groceries", 1:"Medical and Healthcare",2:"Education",3:"Lifestyle and Entertainment",4:"Travel & Transportation",5:"Clothing"}
|
44 |
|
45 |
+
def predict_model(brand):
|
46 |
+
bo,ind = is_str_in(brand,brands)
|
47 |
+
if bo:
|
48 |
+
out = categories[ind]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
|
50 |
+
else:
|
51 |
+
w = fitted_tfidf.transform([brand])
|
|
|
52 |
# print(w)
|
53 |
|
54 |
+
pred = loaded_model.predict(w)
|
55 |
+
out = map_dict[pred[0]]
|
56 |
+
return out
|
57 |
# print(loaded_model.predict(w))
|
58 |
#out = categories[out]
|
59 |
+
|
60 |
+
import time
|
61 |
+
# brand = st.text_input("Enter the name of the brand")
|
62 |
+
# submit = st.form_submit_button('Submit')
|
63 |
+
uploaded_file = st.file_uploader("Choose a file")
|
64 |
+
if uploaded_file is not None:
|
65 |
+
uploaded_file = uploaded_file.getvalue().decode('utf-8').splitlines()
|
66 |
+
# st.write(uploaded_file)
|
67 |
+
|
68 |
+
# print the list
|
69 |
+
#print(content_list)
|
70 |
+
|
71 |
+
# remove new line characters
|
72 |
+
brand_list = [x.strip() for x in uploaded_file]
|
73 |
+
#st.write(" ".join(content_list))
|
74 |
+
st.subheader("Output File")
|
75 |
+
with st.spinner(text="This may take a moment..."):
|
76 |
+
time.sleep(2)
|
77 |
+
out_list = []
|
78 |
+
for brand in brand_list:
|
79 |
+
out_list.append(brand+" -> "+predict_model(brand))
|
80 |
+
|
81 |
+
# bo,ind = is_str_in(brand,brands)
|
82 |
+
# if bo:
|
83 |
+
# out = categories[ind]
|
84 |
+
|
85 |
+
# else:
|
86 |
+
# a,out1,_,_=find_closest_match(brand,brands)
|
87 |
+
# w = fitted_tfidf.transform([brand])
|
88 |
+
# # print(w)
|
89 |
+
|
90 |
+
# pred = loaded_model.predict(w)
|
91 |
+
# out = map_dict[pred[0]]
|
92 |
+
# out = "Normal String matching:"+str(categories[out1])+"\n"+" Model:"+out
|
93 |
+
# print(loaded_model.predict(w))
|
94 |
+
#out = categories[out]
|
95 |
+
|
96 |
+
out = "\n".join(out_list)
|
97 |
+
st.download_button('Download Outputs', out)
|
98 |
|
99 |
#'''
|
100 |
|