jadenhoch commited on
Commit
995cd7e
·
verified ·
1 Parent(s): a9ca19d

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +92 -38
src/streamlit_app.py CHANGED
@@ -1,40 +1,94 @@
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
+ Hugging Face's logo
2
+ Hugging Face
3
+ Models
4
+ Datasets
5
+ Spaces
6
+ Community
7
+ Docs
8
+ Enterprise
9
+ Pricing
10
+
11
+
12
+ Spaces:
13
+ jadenhoch
14
+ /
15
+ Snowflakesnowflake-arctic-embed-m
16
+
17
+
18
+ like
19
+ 0
20
+
21
+ Logs
22
+ App
23
+ Files
24
+ Community
25
+ Settings
26
+ Snowflakesnowflake-arctic-embed-m
27
+ /
28
+ src
29
+ /
30
+ streamlit_app.py
31
+
32
+ jadenhoch's picture
33
+ jadenhoch
34
+ Update src/streamlit_app.py
35
+ fb985ba
36
+ verified
37
+ about 24 hours ago
38
+ raw
39
+
40
+ Copy download link
41
+ history
42
+ blame
43
+ edit
44
+ delete
45
+
46
+ 1.57 kB
47
  import streamlit as st
48
+ import pandas as pd
49
+ import numpy as np
50
+ from sentence_transformers import SentenceTransformer, util
51
+ from huggingface_hub import hf_hub_download
52
+ import os
53
+
54
+ st.set_page_config(page_title="ArXiv Expert Finder", page_icon="🔬", layout="wide")
55
+ st.title("ArXiv Expert Finder")
56
+
57
+ @st.cache_resource
58
+ def load_model():
59
+ return SentenceTransformer("Alibaba-NLP/gte-multilingual-base")
60
+
61
+ @st.cache_data
62
+ def load_data():
63
+ parquet_path = hf_hub_download(
64
+ repo_id="jadenhoch/gte-multilingual-base",
65
+ filename="arxiv_2025_zstd.parquet",
66
+ repo_type="space"
67
+ )
68
+
69
+ npy_path = hf_hub_download(
70
+ repo_id="jadenhoch/gte-multilingual-base",
71
+ filename="gte-multilingual-base.npy",
72
+ repo_type="dataset"
73
+ )
74
+
75
+ return pd.read_parquet(parquet_path), np.load(npy_path)
76
+
77
+ model = load_model()
78
+ df, corpus_embeddings = load_data()
79
+
80
+ top_k = st.sidebar.slider("Number of results", 1, 20, 6)
81
+ query = st.text_area("🔍 Text eingeben:", height=200)
82
 
83
+ if st.button("Suchen") and query:
84
+ query_emb = model.encode(query)
85
+ results = util.semantic_search(query_emb, corpus_embeddings, top_k=top_k)[0]
86
+
87
+ for rank, hit in enumerate(results, 1):
88
+ idx = hit["corpus_id"]
89
+ st.markdown(f"### {rank} | Similarity Score: {hit['score']:.4f} | Index: {idx}")
90
+ st.write(f"**Autoren:** {df.iloc[idx]['authors']}")
91
+ st.write(f"**Titel:** {df.iloc[idx]['title']}")
92
+ with st.expander("Abstract"):
93
+ st.write(df.iloc[idx]['abstract'])
94
+ st.divider()