Spaces:
Sleeping
Sleeping
Nick Sorros
commited on
Commit
·
e18db08
1
Parent(s):
c956188
Return related terms when no results are found
Browse files
app.py
CHANGED
@@ -1,3 +1,5 @@
|
|
|
|
|
|
1 |
from collections import Counter
|
2 |
import streamlit as st
|
3 |
import pandas as pd
|
@@ -31,14 +33,22 @@ if "grants" not in st.session_state:
|
|
31 |
|
32 |
grants = st.session_state["grants"]
|
33 |
|
|
|
|
|
|
|
|
|
|
|
34 |
query = st.text_input("", value="Malaria")
|
35 |
st.button("Search 🔎", on_click=search, kwargs={"query": query})
|
36 |
|
37 |
if "results" in st.session_state:
|
38 |
st.caption("Related MeSH terms")
|
39 |
|
40 |
-
|
41 |
-
|
|
|
|
|
|
|
42 |
|
43 |
columns = st.columns(5)
|
44 |
for row_i in range(3):
|
|
|
1 |
+
import difflib
|
2 |
+
|
3 |
from collections import Counter
|
4 |
import streamlit as st
|
5 |
import pandas as pd
|
|
|
33 |
|
34 |
grants = st.session_state["grants"]
|
35 |
|
36 |
+
if "tags" not in st.session_state:
|
37 |
+
st.session_state["tags"] = list(set([tag for grant in grants for tag in grant["tags"]]))
|
38 |
+
|
39 |
+
tags = st.session_state["tags"]
|
40 |
+
|
41 |
query = st.text_input("", value="Malaria")
|
42 |
st.button("Search 🔎", on_click=search, kwargs={"query": query})
|
43 |
|
44 |
if "results" in st.session_state:
|
45 |
st.caption("Related MeSH terms")
|
46 |
|
47 |
+
if st.session_state["results"]:
|
48 |
+
retrieved_tags = [tag for res in st.session_state["results"] for tag in res["tags"]]
|
49 |
+
most_common_tags = [tag for tag, _ in Counter(retrieved_tags).most_common(20)]
|
50 |
+
else:
|
51 |
+
most_common_tags = difflib.get_close_matches(query, tags, n=20)
|
52 |
|
53 |
columns = st.columns(5)
|
54 |
for row_i in range(3):
|