File size: 1,563 Bytes
b493a01
4709571
 
 
b493a01
4709571
 
 
 
b493a01
4709571
 
b493a01
4709571
 
b493a01
 
 
4709571
b493a01
 
 
4709571
 
 
 
 
 
b493a01
4709571
 
 
 
b493a01
 
 
 
4709571
 
 
 
b493a01
 
 
4709571
 
1
2
3
4
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
41
42
43
44
45
46
47
from collections import Counter
import streamlit as st
import srsly


def search(query):
    results = []
    for grant in grants:
        if query in grant["tags"]:
            results.append({"title": grant["title"], "tags": grant["tags"]})
    st.session_state["results"] = results


st.header("Search πŸ”Ž grants using MeSH πŸ”–")
st.sidebar.header("Information β„Ή")
st.sidebar.write(
    "A complete list of MeSH tags can be found here https://meshb.nlm.nih.gov/treeView"
)
st.sidebar.write("The grants data can be found https://www.threesixtygiving.org/")
st.sidebar.write(
    "The model used to tag grants is https://huggingface.co/Wellcome/WellcomeBertMesh"
)

if "grants" not in st.session_state:
    st.session_state["grants"] = list(srsly.read_jsonl("tagged_grants.jsonl"))

grants = st.session_state["grants"]

query = st.text_input("", value="Malaria")
st.button("Search πŸ”Ž", on_click=search, kwargs={"query": query})

if "results" in st.session_state:
    st.caption("Related MeSH terms")

    retrieved_tags = [tag for res in st.session_state["results"] for tag in res["tags"]]
    most_common_tags = [tag for tag, _ in Counter(retrieved_tags).most_common(20)]

    columns = st.columns(5)
    for row_i in range(3):
        for col_i, col in enumerate(columns):
            with col:
                tag_i = row_i * 5 + col_i
                if tag_i < len(most_common_tags):
                    tag = most_common_tags[tag_i]
                    st.button(tag, on_click=search, kwargs={"query": tag})
    st.table(st.session_state["results"])