Jan Štihec commited on
Commit
1e85b1a
1 Parent(s): bd4f04b

No hits from pubmed fix

Browse files
Files changed (1) hide show
  1. app.py +27 -16
app.py CHANGED
@@ -9,8 +9,8 @@ from langdetect import detect
9
  from typing import Dict, List
10
 
11
 
12
- if "valid_inputs_received" not in st.session_state:
13
- st.session_state["valid_inputs_received"] = False
14
 
15
 
16
  def get_articles(query, fetcher) -> Dict[List[str], List[str]]:
@@ -42,11 +42,11 @@ def get_articles(query, fetcher) -> Dict[List[str], List[str]]:
42
  titles.append(title)
43
  links.append(article_link)
44
  except Exception as e:
45
- logging.warning(f"Error reading article: {article_id}: ", exc_info=e)
46
 
47
  return {
48
- "Conclusions": conclusions,
49
- "Links": links
50
  }
51
 
52
 
@@ -59,30 +59,30 @@ def load_cross_encoder():
59
 
60
  @st.cache_resource
61
  def load_pubmed_fetcher():
62
- pubmed = PubMed(tool="PubmedFactChecker", email="[email protected]")
63
  return pubmed
64
 
65
 
66
  def run_ui():
67
  # This function controls the whole app flow.
68
- st.set_page_config(page_title="PUBMED FACT-CHECKER", page_icon="📖")
69
 
70
  sidebar = st.sidebar
71
  sidebar.title('ABOUT')
72
- sidebar.write("""
73
  The PubMed fact-checker app enables users to verify biomedical claims by comparing them against
74
  research papers available on PubMed. \n
75
  As the number of self-proclaimed experts continues to rise,
76
  so does the risk of harmful misinformation. This app showcases the potential of Large Language Models
77
  to provide accurate and valuable information to people.
78
- """)
79
  sidebar.title('EXAMPLES')
80
  sidebar.write('Try one of the below examples to see PubMed fact-checker in action.')
81
 
82
  st.title('PubMed FACT CHECKER')
83
- with st.form(key="fact_form"):
84
- fact = st.text_input('Fact:', placeholder='Enter your fact')
85
- submitted = st.form_submit_button("Fact-Check")
86
 
87
  if sidebar.button('Mediterranean diet helps with weight loss.', use_container_width=250):
88
  submitted = True
@@ -97,7 +97,7 @@ def run_ui():
97
  fact = 'Vaccines are a cause of autism.'
98
 
99
  sidebar.title('HOW IT WORKS')
100
- sidebar.write('Source code and in-depth app description available at:')
101
  sidebar.info('**GitHub: [@jacinthes](https://github.com/jacinthes/slovene-nli-benchmark)**', icon="💻")
102
  sidebar.title('DISCLAIMER')
103
  sidebar.write('This project is meant for educational and research purposes. \n'
@@ -112,7 +112,8 @@ def run_ui():
112
  st.stop()
113
 
114
  elif submitted and not detect(fact) == 'en':
115
- st.warning('Please enter valid text in English. For short inputs, language detection is sometimes inaccurate.')
 
116
  st.session_state.valid_inputs_received = False
117
  st.stop()
118
 
@@ -130,7 +131,17 @@ def run_ui():
130
 
131
  article_conclusions = articles['Conclusions']
132
  article_links = articles['Links']
 
 
 
 
 
 
 
 
 
133
  cross_inp = [[fact, conclusions] for conclusions in article_conclusions]
 
134
  with st.spinner('Assessing article relevancy...'):
135
  cross_encoder = load_cross_encoder()
136
  cross_scores = cross_encoder.predict(cross_inp) # Calculate relevancy using the defined cross-encoder.
@@ -142,7 +153,7 @@ def run_ui():
142
  })
143
  df.sort_values(by=['Score'], ascending=False, inplace=True)
144
  df = df[df['Score'] > 0] # Only keep articles with relevancy score above 0.
145
- if df.shape[0] == 0: # If no relevant article si found, inform the user.
146
  st.info(
147
  "Unfortunately, I couldn't find anything for your search.\n"
148
  "Don't let that discourage you, I have over 35 million citations in my database.\n"
@@ -151,7 +162,7 @@ def run_ui():
151
  st.stop()
152
 
153
  df = df.head(10) # Keep only 10 most relevant articles. This is done to control OpenAI costs and load time.
154
- progress_text = "Assessing the validity of the fact based on relevant research papers."
155
  fact_checking_bar = st.progress(0, text=progress_text)
156
  step = 100/df.shape[0]
157
  percent_complete = 0
 
9
  from typing import Dict, List
10
 
11
 
12
+ if 'valid_inputs_received' not in st.session_state:
13
+ st.session_state['valid_inputs_received'] = False
14
 
15
 
16
  def get_articles(query, fetcher) -> Dict[List[str], List[str]]:
 
42
  titles.append(title)
43
  links.append(article_link)
44
  except Exception as e:
45
+ logging.warning(f'Error reading article: {article_id}: ', exc_info=e)
46
 
47
  return {
48
+ 'Conclusions': conclusions,
49
+ 'Links': links
50
  }
51
 
52
 
 
59
 
60
  @st.cache_resource
61
  def load_pubmed_fetcher():
62
+ pubmed = PubMed(tool='PubmedFactChecker', email='[email protected]')
63
  return pubmed
64
 
65
 
66
  def run_ui():
67
  # This function controls the whole app flow.
68
+ st.set_page_config(page_title='PUBMED FACT-CHECKER', page_icon='📖')
69
 
70
  sidebar = st.sidebar
71
  sidebar.title('ABOUT')
72
+ sidebar.write('''
73
  The PubMed fact-checker app enables users to verify biomedical claims by comparing them against
74
  research papers available on PubMed. \n
75
  As the number of self-proclaimed experts continues to rise,
76
  so does the risk of harmful misinformation. This app showcases the potential of Large Language Models
77
  to provide accurate and valuable information to people.
78
+ ''')
79
  sidebar.title('EXAMPLES')
80
  sidebar.write('Try one of the below examples to see PubMed fact-checker in action.')
81
 
82
  st.title('PubMed FACT CHECKER')
83
+ with st.form(key='fact_form'):
84
+ fact = st.text_input('Fact:', placeholder='Enter your fact', key='form_input')
85
+ submitted = st.form_submit_button('Fact-Check')
86
 
87
  if sidebar.button('Mediterranean diet helps with weight loss.', use_container_width=250):
88
  submitted = True
 
97
  fact = 'Vaccines are a cause of autism.'
98
 
99
  sidebar.title('HOW IT WORKS')
100
+ sidebar.write('Source code and an in-depth app description available at:')
101
  sidebar.info('**GitHub: [@jacinthes](https://github.com/jacinthes/slovene-nli-benchmark)**', icon="💻")
102
  sidebar.title('DISCLAIMER')
103
  sidebar.write('This project is meant for educational and research purposes. \n'
 
112
  st.stop()
113
 
114
  elif submitted and not detect(fact) == 'en':
115
+ st.warning('Please enter valid text in English. For short inputs, language detection is sometimes inaccurate.'
116
+ ' Try making the fact more verbose.')
117
  st.session_state.valid_inputs_received = False
118
  st.stop()
119
 
 
131
 
132
  article_conclusions = articles['Conclusions']
133
  article_links = articles['Links']
134
+ if len(article_conclusions) == 0:
135
+ # If nothing is returned by pymed, inform user.
136
+ st.info(
137
+ "Unfortunately, I couldn't find anything for your search.\n"
138
+ "Don't let that discourage you, I have over 35 million citations in my database.\n"
139
+ "I am sure your next search will be more successful."
140
+ )
141
+ st.stop()
142
+
143
  cross_inp = [[fact, conclusions] for conclusions in article_conclusions]
144
+
145
  with st.spinner('Assessing article relevancy...'):
146
  cross_encoder = load_cross_encoder()
147
  cross_scores = cross_encoder.predict(cross_inp) # Calculate relevancy using the defined cross-encoder.
 
153
  })
154
  df.sort_values(by=['Score'], ascending=False, inplace=True)
155
  df = df[df['Score'] > 0] # Only keep articles with relevancy score above 0.
156
+ if df.shape[0] == 0: # If no relevant article is found, inform the user.
157
  st.info(
158
  "Unfortunately, I couldn't find anything for your search.\n"
159
  "Don't let that discourage you, I have over 35 million citations in my database.\n"
 
162
  st.stop()
163
 
164
  df = df.head(10) # Keep only 10 most relevant articles. This is done to control OpenAI costs and load time.
165
+ progress_text = 'Assessing the validity of the fact based on relevant research papers.'
166
  fact_checking_bar = st.progress(0, text=progress_text)
167
  step = 100/df.shape[0]
168
  percent_complete = 0