jadenhoch commited on
Commit
77d191a
·
verified ·
1 Parent(s): ad7c1d7

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. 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
- # Welcome to Streamlit!
8
-
9
- Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
10
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
11
- forums](https://discuss.streamlit.io).
12
-
13
- In the meantime, below is an example of what you can do with just a few lines of code:
14
- """
15
-
16
- num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
17
- num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
18
-
19
- indices = np.linspace(0, 1, num_points)
20
- theta = 2 * np.pi * num_turns * indices
21
- radius = indices
22
-
23
- x = radius * np.cos(theta)
24
- y = radius * np.sin(theta)
25
-
26
- df = pd.DataFrame({
27
- "x": x,
28
- "y": y,
29
- "idx": indices,
30
- "rand": np.random.randn(num_points),
31
- })
32
-
33
- st.altair_chart(alt.Chart(df, height=700, width=700)
34
- .mark_point(filled=True)
35
- .encode(
36
- x=alt.X("x", axis=None),
37
- y=alt.Y("y", axis=None),
38
- color=alt.Color("idx", legend=None, scale=alt.Scale()),
39
- size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
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()