Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +47 -39
src/streamlit_app.py
CHANGED
|
@@ -1,40 +1,48 @@
|
|
| 1 |
-
import altair as alt
|
| 2 |
-
import numpy as np
|
| 3 |
-
import pandas as pd
|
| 4 |
import streamlit as st
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import numpy as np
|
| 4 |
+
from sentence_transformers import SentenceTransformer, util
|
| 5 |
+
from huggingface_hub import hf_hub_download
|
| 6 |
+
import os
|
| 7 |
+
|
| 8 |
+
st.set_page_config(page_title="ArXiv Expert Finder", page_icon="🔬", layout="wide")
|
| 9 |
+
st.title("ArXiv Expert Finder")
|
| 10 |
+
|
| 11 |
+
@st.cache_resource
|
| 12 |
+
def load_model():
|
| 13 |
+
return SentenceTransformer("bisectgroup/BiCA-base")
|
| 14 |
+
|
| 15 |
+
@st.cache_data
|
| 16 |
+
def load_data():
|
| 17 |
+
parquet_path = hf_hub_download(
|
| 18 |
+
repo_id="jadenhoch/Expert-Finder-BiCA-base",
|
| 19 |
+
filename="arxiv_2025_zstd.parquet",
|
| 20 |
+
repo_type="space"
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
npy_path = hf_hub_download(
|
| 24 |
+
repo_id="jadenhoch/BiCA-base",
|
| 25 |
+
filename="BiCA-base.npy",
|
| 26 |
+
repo_type="dataset"
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
return pd.read_parquet(parquet_path), np.load(npy_path)
|
| 30 |
+
|
| 31 |
+
model = load_model()
|
| 32 |
+
df, corpus_embeddings = load_data()
|
| 33 |
+
|
| 34 |
+
top_k = st.sidebar.slider("Number of results", 1, 20, 6)
|
| 35 |
+
query = st.text_area("🔍 Text eingeben:", height=200)
|
| 36 |
+
|
| 37 |
+
if st.button("Suchen") and query:
|
| 38 |
+
query_emb = model.encode(query)
|
| 39 |
+
results = util.semantic_search(query_emb, corpus_embeddings, top_k=top_k)[0]
|
| 40 |
+
|
| 41 |
+
for rank, hit in enumerate(results, 1):
|
| 42 |
+
idx = hit["corpus_id"]
|
| 43 |
+
st.markdown(f"### {rank} | Similarity Score: {hit['score']:.4f} | Index: {idx}")
|
| 44 |
+
st.write(f"**Autoren:** {df.iloc[idx]['authors']}")
|
| 45 |
+
st.write(f"**Titel:** {df.iloc[idx]['title']}")
|
| 46 |
+
with st.expander("Abstract"):
|
| 47 |
+
st.write(df.iloc[idx]['abstract'])
|
| 48 |
+
st.divider()
|