KAI MAURIN-JONES commited on
Commit
2e462a5
1 Parent(s): bf84cfc

app updated

Browse files
Files changed (1) hide show
  1. wiki_game_st_bs4.py +6 -2
wiki_game_st_bs4.py CHANGED
@@ -51,7 +51,11 @@ def play_wiki_game(starting_topic: str, target_topic: str, limit: int = 100):
51
  if num_pages > 1:
52
  page_source = get_wikipedia_page(topic)
53
 
54
- context_sentence = get_topic_context(page_source)
 
 
 
 
55
  links_texts = []
56
 
57
  soup = BeautifulSoup(page_source, 'html.parser')
@@ -88,7 +92,7 @@ def play_wiki_game(starting_topic: str, target_topic: str, limit: int = 100):
88
  if num_pages == limit:
89
  st.write("\n" + "-" * 150)
90
  st.write(f"\nUnfortunately, the model couldn't get from '{starting_topic.title()}', to '{target_topic.title()}' in {num_pages} pages or less.")
91
- st.write(f"In {round(time.time() - start_time, 2)} seconds, it got from '{starting_topic.title()}': 'https://en.wikipedia.org/wiki/{starting_topic}', to '{target_topic.title()}': '{used_links[-1]}'")
92
  st.write(f"\nTry a different combination to see if it can do it!\n")
93
  st.write("-" * 150)
94
  break
 
51
  if num_pages > 1:
52
  page_source = get_wikipedia_page(topic)
53
 
54
+ try:
55
+ context_sentence = get_topic_context(page_source)
56
+ except Exception as e:
57
+ print("Context could not be found from webpage")
58
+
59
  links_texts = []
60
 
61
  soup = BeautifulSoup(page_source, 'html.parser')
 
92
  if num_pages == limit:
93
  st.write("\n" + "-" * 150)
94
  st.write(f"\nUnfortunately, the model couldn't get from '{starting_topic.title()}', to '{target_topic.title()}' in {num_pages} pages or less.")
95
+ st.write(f"In {round(time.time() - start_time, 2)} seconds, it got from '{starting_topic.title()}': '{used_links[0]}', to '{target_topic.title()}': '{used_links[-1]}'")
96
  st.write(f"\nTry a different combination to see if it can do it!\n")
97
  st.write("-" * 150)
98
  break