Spaces:
Sleeping
Sleeping
File size: 6,169 Bytes
13d6d96 e0f3355 13d6d96 e0f3355 13d6d96 e0f3355 13d6d96 e0f3355 13d6d96 e0f3355 13d6d96 e0f3355 747bf26 e0f3355 13d6d96 747bf26 e0f3355 747bf26 e0f3355 747bf26 e0f3355 747bf26 13d6d96 747bf26 e0f3355 13d6d96 e0f3355 747bf26 13d6d96 747bf26 13d6d96 747bf26 e0f3355 13d6d96 e0f3355 13d6d96 e0f3355 13d6d96 e0f3355 13d6d96 747bf26 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
import streamlit as st
import pandas as pd
import matplotlib.pyplot as plt
from wordcloud import WordCloud
from tools import sourceformat as sf
# ===config===
st.set_page_config(
page_title="Coconut",
page_icon="🥥",
layout="wide",
initial_sidebar_state="collapsed"
)
hide_streamlit_style = """
<style>
#MainMenu
{visibility: hidden;}
footer {visibility: hidden;}
[data-testid="collapsedControl"] {display: none}
</style>
"""
st.markdown(hide_streamlit_style, unsafe_allow_html=True)
with st.popover("🔗 Menu"):
st.page_link("https://www.coconut-libtool.com/", label="Home", icon="🏠")
st.page_link("pages/1 Scattertext.py", label="Scattertext", icon="1️⃣")
st.page_link("pages/2 Topic Modeling.py", label="Topic Modeling", icon="2️⃣")
st.page_link("pages/3 Bidirected Network.py", label="Bidirected Network", icon="3️⃣")
st.page_link("pages/4 Sunburst.py", label="Sunburst", icon="4️⃣")
st.page_link("pages/5 Burst Detection.py", label="Burst Detection", icon="5️⃣")
st.page_link("pages/6 Keywords Stem.py", label="Keywords Stem", icon="6️⃣")
st.page_link("pages/7 Sentiment Analysis.py", label="Sentiment Analysis", icon="7️⃣")
st.page_link("pages/8 Shifterator.py", label="Shifterator", icon="8️⃣")
st.page_link("pages/9 Summarization.py", label = "Summarization",icon ="9️⃣")
st.page_link("pages/10 WordCloud.py", label = "WordCloud", icon = "🔟")
st.header("Wordcloud", anchor=False)
st.subheader('Put your file here...', anchor=False)
#========unique id========
@st.cache_resource(ttl=3600)
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])
@st.cache_data(ttl=3600)
def get_ext(uploaded_file):
extype = uID+uploaded_file.name
return extype
#===clear cache===
def reset_all():
st.cache_data.clear()
#===text reading===
@st.cache_data(ttl=3600)
def read_txt(intext):
return (intext.read()).decode()
@st.cache_data(ttl=3600)
def conv_txt(extype):
if("PMID" in (uploaded_file.read()).decode()):
uploaded_file.seek(0)
papers = sf.medline(uploaded_file)
print(papers)
return papers
col_dict = {'TI': 'Title',
'SO': 'Source title',
'DE': 'Author Keywords',
'DT': 'Document Type',
'AB': 'Abstract',
'TC': 'Cited by',
'PY': 'Year',
'ID': 'Keywords Plus',
'rights_date_used': 'Year'}
uploaded_file.seek(0)
papers = pd.read_csv(uploaded_file, sep='\t')
#if text just has one column (or is not csv) return nothing
if(len(papers.columns)==1):
return
if("htid" in papers.columns):
papers = sf.htrc(papers)
papers.rename(columns=col_dict, inplace=True)
print(papers)
return papers
#===csv reading===
@st.cache_data(ttl=3600)
def upload(file):
papers = pd.read_csv(uploaded_file)
if "About the data" in papers.columns[0]:
papers = sf.dim(papers)
col_dict = {'MeSH terms': 'Keywords',
'PubYear': 'Year',
'Times cited': 'Cited by',
'Publication Type': 'Document Type'
}
papers.rename(columns=col_dict, inplace=True)
return papers
#===Read data===
uploaded_file = st.file_uploader('', type=['txt','csv'], on_change=reset_all)
if uploaded_file is not None:
tab1, tab2, tab3 = st.tabs(["📈 Generate visualization", "📃 Reference", "⬇️ Download Help"])
with tab1:
c1, c2 = st.columns(2)
with c1:
max_font = st.number_input("Max Font Size", min_value = 1, value = 100)
max_words = st.number_input("Max Word Count", min_value = 1, value = 250)
background = st.selectbox("Background color", ["white","black"])
with c2:
words_to_remove = st.text_input("Remove specific words. Separate words by semicolons (;)")
stopwords = words_to_remove.split(';')
image_width = st.number_input("Image width", value = 400)
image_height = st.number_input("Image height", value = 200)
scale = st.number_input("Scale", value = 1)
try:
extype = get_ext(uploaded_file)
if extype.endswith(".txt"):
try:
texts = conv_txt(uploaded_file)
colcho = c1.selectbox("Choose Column", list(texts))
fulltext = " ".join(list(texts[colcho]))
except:
fulltext = read_txt(uploaded_file)
if st.button("Submit"):
wordcloud = WordCloud(max_font_size = max_font,
max_words = max_words,
background_color=background,
stopwords = stopwords,
height = image_height,
width = image_width,
scale = scale).generate(fulltext)
img = wordcloud.to_image()
with st.container(border=True):
st.image(img, use_container_width=True)
elif extype.endswith(".csv"):
texts = upload(uploaded_file)
colcho = c1.selectbox("Choose Column", list(texts))
fullcolumn = " ".join(list(texts[colcho]))
if st.button("Submit"):
wordcloud = WordCloud(max_font_size = max_font,
max_words = max_words,
background_color=background,
stopwords = stopwords,
height = image_height,
width = image_width,
scale = scale).generate(fullcolumn)
img = wordcloud.to_image()
with st.container(border=True):
st.image(img, use_container_width=True)
except Exception as e:
st.write(e) |