Spaces:
Sleeping
Sleeping
File size: 4,085 Bytes
63994d4 7aaa1ae 63994d4 230629e 63994d4 2ebc879 885f549 63994d4 2ebc879 230629e 885f549 47d9b77 63994d4 230629e 63994d4 230629e 63994d4 230629e 63994d4 230629e 63994d4 230629e 63994d4 |
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 |
"""
Reference: https://huggingface.co/spaces/gwf-uwaterloo/acl-spectrum (By Ehsan Khamallo)
"""
import os
import re
import pandas as pd
import plotly.express as px
import streamlit as st
st.set_page_config(layout="wide")
DATA_FILE = "hess_papers_details.json"
st.markdown(
"""
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha256-DF7Zhf293AJxJNTmh5zhoYYIMs2oXitRfBjY+9L//AY=" crossorigin="anonymous">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Permanent+Marker&display=swap" rel="stylesheet">
<style>
.title {
font-family: 'Arial';
font-size: 2.0rem;
}
</style>""",
unsafe_allow_html=True,
)
st.sidebar.write(
"""<center><p class="title">
Clustering on HESS Papers 🌎🌿
</p></center>""",
unsafe_allow_html=True,
)
st.sidebar.write(
"""<p class="text-justify">
A clustered visualization of all papers submitted to the
<a href=https://www.hydrology-and-earth-system-sciences.net/>Hydrology and Earth System Sciences</a> (HESS) conference.
5318 papers are embedded using <a href="https://huggingface.co/allenai/specter2_base">spectre2</a> and reduced with
t-SNE. Papers span from as early as 1997 to 2023.
</p>""",
unsafe_allow_html=True,
)
def to_string_authors(list_of_authors):
if len(list_of_authors) > 5:
return ", ".join(list_of_authors[:5]) + ", et al."
elif len(list_of_authors) > 2:
return ", ".join(list_of_authors[:-1]) + ", and " + list_of_authors[-1]
else:
return " and ".join(list_of_authors)
def load_df(data_file: os.PathLike):
df = pd.read_json(data_file, orient="records")
df["x"] = df["t-SNE1"]
df["y"] = df["t-SNE2"]
df["authors_trimmed"] = df["authors_trimmed"]
# #sort dataframe by year
# df['year'] = pd.to_datetime(df['year'])
# df = df.sort_values('year', ascending=True)
# df['year'] = df['year'].dt.strftime('%Y')
#df['year'] = df['year'].astype(int)
return df
@st.cache_data
def load_dataframe():
return load_df(DATA_FILE)
DF = load_dataframe()
DF["opacity"] = 0.04
min_year, max_year = DF["year"].min(), DF["year"].max()
with st.sidebar:
author_names = st.text_input("Author names (separated by comma)")
title = st.text_input("Title")
# Work on this
# topics = st.multiselect(
# "Topics",
# ["Topics 1: "],
# ["Topics 2: "],
# )
start_year, end_year = st.select_slider(
"Publication year",
options=[str(y) for y in range(min_year, max_year + 1)],
value=(str(min_year), str(max_year)),
)
start_year = int(start_year)
end_year = int(end_year)
df_mask = (DF["year"] >= start_year) & (DF["year"] <= end_year)
if author_names:
authors = [a.strip() for a in author_names.split(",")]
author_mask = DF.authors.apply(
lambda row: all(any(re.match(rf".*{a}.*", x, re.IGNORECASE) for x in row) for a in authors)
)
df_mask = df_mask & author_mask
if title:
df_mask = df_mask & DF.title.apply(lambda x: title.lower() in x.lower())
DF.loc[df_mask, "opacity"] = 1.0
st.write(f"Number of points: {DF[df_mask].shape[0]}")
fig = px.scatter(
DF,
x="x",
y="y",
opacity=DF["opacity"],
color=DF["cluster"],
width=1000,
height=800,
custom_data=("title", "authors_trimmed", "year"),
color_continuous_scale="haline",
)
fig.update_traces(
hovertemplate="<b>%{customdata[0]}</b><br>%{customdata[1]}<br>%{customdata[2]}<br><i>"
)
fig.update_layout(
showlegend=False,
font=dict(
family="Times New Roman",
size=30,
),
hoverlabel=dict(
align="left",
font_size=14,
font_family="Rockwell",
namelength=-1,
),
)
fig.update_xaxes(title="")
fig.update_yaxes(title="")
st.plotly_chart(fig, use_container_width=True)
|