Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +51 -6
src/streamlit_app.py
CHANGED
|
@@ -4,6 +4,12 @@ from sentence_transformers import SentenceTransformer
|
|
| 4 |
import numpy as np
|
| 5 |
from collections import defaultdict
|
| 6 |
import time
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
# Page config
|
| 9 |
st.set_page_config(
|
|
@@ -16,12 +22,13 @@ st.set_page_config(
|
|
| 16 |
@st.cache_resource
|
| 17 |
def load_model():
|
| 18 |
"""Load the sentence transformer model"""
|
| 19 |
-
return SentenceTransformer('all-MiniLM-L6-v2')
|
| 20 |
|
| 21 |
@st.cache_data(ttl=3600)
|
| 22 |
-
def search_openalex_papers(query, num_results=50):
|
| 23 |
"""
|
| 24 |
Search OpenAlex for papers related to the query
|
|
|
|
| 25 |
"""
|
| 26 |
base_url = "https://api.openalex.org/works"
|
| 27 |
|
|
@@ -32,6 +39,10 @@ def search_openalex_papers(query, num_results=50):
|
|
| 32 |
"mailto": "user@example.com" # Polite pool
|
| 33 |
}
|
| 34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
try:
|
| 36 |
response = requests.get(base_url, params=params, timeout=30)
|
| 37 |
response.raise_for_status()
|
|
@@ -185,13 +196,47 @@ def main():
|
|
| 185 |
|
| 186 |
**How it works:**
|
| 187 |
1. Enter your search terms (e.g., "machine learning for drug discovery")
|
| 188 |
-
2.
|
| 189 |
-
3.
|
|
|
|
| 190 |
""")
|
| 191 |
|
| 192 |
# Sidebar controls
|
| 193 |
st.sidebar.header("Search Settings")
|
| 194 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 195 |
num_papers = st.sidebar.slider(
|
| 196 |
"Number of papers to fetch",
|
| 197 |
min_value=20,
|
|
@@ -240,8 +285,8 @@ def main():
|
|
| 240 |
model = load_model()
|
| 241 |
|
| 242 |
# Search papers
|
| 243 |
-
with st.spinner(f"Searching OpenAlex for papers about '{query}'..."):
|
| 244 |
-
papers = search_openalex_papers(query, num_papers)
|
| 245 |
|
| 246 |
if not papers:
|
| 247 |
st.warning("No papers found. Try different search terms.")
|
|
|
|
| 4 |
import numpy as np
|
| 5 |
from collections import defaultdict
|
| 6 |
import time
|
| 7 |
+
import os
|
| 8 |
+
|
| 9 |
+
# Set cache directory to writable location
|
| 10 |
+
os.environ['HF_HOME'] = '/tmp/huggingface'
|
| 11 |
+
os.environ['TRANSFORMERS_CACHE'] = '/tmp/huggingface'
|
| 12 |
+
os.environ['SENTENCE_TRANSFORMERS_HOME'] = '/tmp/huggingface'
|
| 13 |
|
| 14 |
# Page config
|
| 15 |
st.set_page_config(
|
|
|
|
| 22 |
@st.cache_resource
|
| 23 |
def load_model():
|
| 24 |
"""Load the sentence transformer model"""
|
| 25 |
+
return SentenceTransformer('all-MiniLM-L6-v2', cache_folder='/tmp/huggingface')
|
| 26 |
|
| 27 |
@st.cache_data(ttl=3600)
|
| 28 |
+
def search_openalex_papers(query, num_results=50, country_code=None):
|
| 29 |
"""
|
| 30 |
Search OpenAlex for papers related to the query
|
| 31 |
+
Optionally filter by author's country
|
| 32 |
"""
|
| 33 |
base_url = "https://api.openalex.org/works"
|
| 34 |
|
|
|
|
| 39 |
"mailto": "user@example.com" # Polite pool
|
| 40 |
}
|
| 41 |
|
| 42 |
+
# Add country filter if specified
|
| 43 |
+
if country_code:
|
| 44 |
+
params["filter"] = f"authorships.countries:{country_code}"
|
| 45 |
+
|
| 46 |
try:
|
| 47 |
response = requests.get(base_url, params=params, timeout=30)
|
| 48 |
response.raise_for_status()
|
|
|
|
| 196 |
|
| 197 |
**How it works:**
|
| 198 |
1. Enter your search terms (e.g., "machine learning for drug discovery")
|
| 199 |
+
2. Optionally filter by author country
|
| 200 |
+
3. The app finds relevant papers using semantic similarity
|
| 201 |
+
4. Authors are ranked by relevance, h-index, and citation metrics
|
| 202 |
""")
|
| 203 |
|
| 204 |
# Sidebar controls
|
| 205 |
st.sidebar.header("Search Settings")
|
| 206 |
|
| 207 |
+
# Country filter
|
| 208 |
+
country_options = {
|
| 209 |
+
"Any Country": None,
|
| 210 |
+
"United States": "US",
|
| 211 |
+
"United Kingdom": "GB",
|
| 212 |
+
"Germany": "DE",
|
| 213 |
+
"France": "FR",
|
| 214 |
+
"Canada": "CA",
|
| 215 |
+
"Australia": "AU",
|
| 216 |
+
"China": "CN",
|
| 217 |
+
"Japan": "JP",
|
| 218 |
+
"India": "IN",
|
| 219 |
+
"South Korea": "KR",
|
| 220 |
+
"Netherlands": "NL",
|
| 221 |
+
"Switzerland": "CH",
|
| 222 |
+
"Sweden": "SE",
|
| 223 |
+
"Italy": "IT",
|
| 224 |
+
"Spain": "ES",
|
| 225 |
+
"Brazil": "BR",
|
| 226 |
+
"Singapore": "SG",
|
| 227 |
+
"Israel": "IL",
|
| 228 |
+
"Belgium": "BE",
|
| 229 |
+
"Austria": "AT",
|
| 230 |
+
}
|
| 231 |
+
|
| 232 |
+
selected_country = st.sidebar.selectbox(
|
| 233 |
+
"Filter by author country",
|
| 234 |
+
options=list(country_options.keys()),
|
| 235 |
+
help="Filter papers by the country of at least one author. Uses ISO country codes from OpenAlex data."
|
| 236 |
+
)
|
| 237 |
+
|
| 238 |
+
country_code = country_options[selected_country]
|
| 239 |
+
|
| 240 |
num_papers = st.sidebar.slider(
|
| 241 |
"Number of papers to fetch",
|
| 242 |
min_value=20,
|
|
|
|
| 285 |
model = load_model()
|
| 286 |
|
| 287 |
# Search papers
|
| 288 |
+
with st.spinner(f"Searching OpenAlex for papers about '{query}'{' from ' + selected_country if country_code else ''}..."):
|
| 289 |
+
papers = search_openalex_papers(query, num_papers, country_code)
|
| 290 |
|
| 291 |
if not papers:
|
| 292 |
st.warning("No papers found. Try different search terms.")
|