Update pages/upload_file.py
Browse files- pages/upload_file.py +76 -1
pages/upload_file.py
CHANGED
@@ -1,2 +1,77 @@
|
|
1 |
import streamlit as st
|
2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
from io import StringIO
|
4 |
+
import json
|
5 |
+
from transformers import pipeline
|
6 |
+
#from transformers import AutoTokenizer, AutoModelForTokenClassification
|
7 |
+
|
8 |
+
def on_click():
|
9 |
+
st.session_state.user_input = ""
|
10 |
+
|
11 |
+
#@st.cache
|
12 |
+
def convert_df(df:pd.DataFrame):
|
13 |
+
return df.to_csv(index=False).encode('utf-8')
|
14 |
+
|
15 |
+
#@st.cache
|
16 |
+
def convert_json(df:pd.DataFrame):
|
17 |
+
result = df.to_json(orient="index")
|
18 |
+
parsed = json.loads(result)
|
19 |
+
json_string = json.dumps(parsed)
|
20 |
+
#st.json(json_string, expanded=True)
|
21 |
+
return json_string
|
22 |
+
|
23 |
+
#st.title("πSBS mapper")
|
24 |
+
st.header("Work in Progress")
|
25 |
+
|
26 |
+
uploaded_file = st.file_uploader(label = "Upload single csv file")
|
27 |
+
if uploaded_file is not None:
|
28 |
+
stringio = StringIO(uploaded_file.getvalue().decode("utf-8"))
|
29 |
+
string_data = stringio.read()
|
30 |
+
st.success('Your file input is: '+ string_data, icon="β
")
|
31 |
+
|
32 |
+
|
33 |
+
#my_model_results = pipeline("ner", model= "checkpoint-92")
|
34 |
+
HuggingFace_model_results = pipeline("ner", model = "blaze999/Medical-NER")
|
35 |
+
|
36 |
+
|
37 |
+
createNER_button = st.button("Map to SBS codes")
|
38 |
+
|
39 |
+
col1, col2, col3 = st.columns([1,1.5,1])
|
40 |
+
col1.subheader("SBS code V2.0")
|
41 |
+
col2.subheader("SBS description v2.0")
|
42 |
+
col3.subheader("Similarity score")
|
43 |
+
|
44 |
+
if uploaded_file is not None and createNER_button == True:
|
45 |
+
dict1 = {"word": [], "entity": []}
|
46 |
+
dict2 = {"word": [], "entity": []}
|
47 |
+
#stringio = StringIO(uploaded_file.getvalue().decode("utf-8"))
|
48 |
+
#string_data = stringio.read()
|
49 |
+
#st.write("Your input is: ", string_data)
|
50 |
+
#with col1:
|
51 |
+
# #st.write(my_model_results(string_data))
|
52 |
+
# #col1.subheader("myDemo Model")
|
53 |
+
# #for result in my_model_results(string_data):
|
54 |
+
# # st.write(result['word'], result['entity'])
|
55 |
+
# # dict1["word"].append(result['word']), dict1["entity"].append(result['entity'])
|
56 |
+
# #df1 = pd.DataFrame.from_dict(dict1)
|
57 |
+
# #st.write(df1)
|
58 |
+
with col2:
|
59 |
+
#st.write(HuggingFace_model_results(string_data))
|
60 |
+
#col2.subheader("Hugging Face Model")
|
61 |
+
for result in HuggingFace_model_results(string_data):
|
62 |
+
st.write(result['word'], result['entity'])
|
63 |
+
dict2["word"].append(result['word']), dict2["entity"].append(result['entity'])
|
64 |
+
df2 = pd.DataFrame.from_dict(dict2)
|
65 |
+
#st.write(df2)
|
66 |
+
|
67 |
+
|
68 |
+
cs, c1, c2, c3, cLast = st.columns([0.75, 1.5, 1.5, 1.5, 0.75])
|
69 |
+
with c1:
|
70 |
+
#csvbutton = download_button(results, "results.csv", "π₯ Download .csv")
|
71 |
+
csvbutton = st.download_button(label="π₯ Download .csv", data=convert_df(df1), file_name= "results.csv", mime='text/csv', key='csv')
|
72 |
+
with c2:
|
73 |
+
#textbutton = download_button(results, "results.txt", "π₯ Download .txt")
|
74 |
+
textbutton = st.download_button(label="π₯ Download .txt", data=convert_df(df1), file_name= "results.text", mime='text/plain', key='text')
|
75 |
+
with c3:
|
76 |
+
#jsonbutton = download_button(results, "results.json", "π₯ Download .json")
|
77 |
+
jsonbutton = st.download_button(label="π₯ Download .json", data=convert_json(df1), file_name= "results.json", mime='application/json', key='json')
|