Spaces:
Running
Running
KAI MAURIN-JONES
commited on
Commit
•
8f7c025
1
Parent(s):
bb120ba
app updated
Browse files- wiki_game_st_bs4.py +8 -8
wiki_game_st_bs4.py
CHANGED
@@ -23,7 +23,10 @@ def most_similar_sentence(target_topic, labels_list):
|
|
23 |
return labels_list[most_similar_index], similarities[most_similar_index], most_similar_index
|
24 |
|
25 |
def get_wikipedia_page(query):
|
26 |
-
|
|
|
|
|
|
|
27 |
return response.text
|
28 |
|
29 |
def get_topic_context(page_source):
|
@@ -54,7 +57,7 @@ def play_wiki_game(starting_topic: str, target_topic: str, limit: int = 100):
|
|
54 |
|
55 |
if num_pages > 1:
|
56 |
# load url to new page of next topic
|
57 |
-
page_source = get_wikipedia_page(
|
58 |
|
59 |
# create backup list of links and texts from previous page in case new current page fails
|
60 |
prev_links_texts = links_texts.pop(loc_idx) # removes the previously used topic
|
@@ -80,6 +83,7 @@ def play_wiki_game(starting_topic: str, target_topic: str, limit: int = 100):
|
|
80 |
links_texts.append((link_url, link_text))
|
81 |
|
82 |
# st.write(f'links_texts length: {len(links_texts)}')
|
|
|
83 |
if len(links_texts) == 0 and num_pages > 1: # if no links
|
84 |
links_texts = prev_links_texts
|
85 |
|
@@ -118,10 +122,6 @@ def play_wiki_game(starting_topic: str, target_topic: str, limit: int = 100):
|
|
118 |
used_links.append(next_link)
|
119 |
used_topics.append(topic)
|
120 |
|
121 |
-
starting_topic = "soulja boy"
|
122 |
-
target_topic = "game"
|
123 |
-
play_wiki_game(starting_topic = starting_topic, target_topic = target_topic, limit = 100)
|
124 |
-
|
125 |
# starting_topic = "soulja boy"
|
126 |
-
# target_topic = "
|
127 |
-
# play_wiki_game(starting_topic = starting_topic, target_topic = target_topic, limit =
|
|
|
23 |
return labels_list[most_similar_index], similarities[most_similar_index], most_similar_index
|
24 |
|
25 |
def get_wikipedia_page(query):
|
26 |
+
if "wikipedia" not in query:
|
27 |
+
response = requests.get(f"https://en.wikipedia.org/wiki/{query}")
|
28 |
+
else:
|
29 |
+
response = requests.get(query)
|
30 |
return response.text
|
31 |
|
32 |
def get_topic_context(page_source):
|
|
|
57 |
|
58 |
if num_pages > 1:
|
59 |
# load url to new page of next topic
|
60 |
+
page_source = get_wikipedia_page(used_links[-1])
|
61 |
|
62 |
# create backup list of links and texts from previous page in case new current page fails
|
63 |
prev_links_texts = links_texts.pop(loc_idx) # removes the previously used topic
|
|
|
83 |
links_texts.append((link_url, link_text))
|
84 |
|
85 |
# st.write(f'links_texts length: {len(links_texts)}')
|
86 |
+
prev_links_texts = []
|
87 |
if len(links_texts) == 0 and num_pages > 1: # if no links
|
88 |
links_texts = prev_links_texts
|
89 |
|
|
|
122 |
used_links.append(next_link)
|
123 |
used_topics.append(topic)
|
124 |
|
|
|
|
|
|
|
|
|
125 |
# starting_topic = "soulja boy"
|
126 |
+
# target_topic = "game"
|
127 |
+
# play_wiki_game(starting_topic = starting_topic, target_topic = target_topic, limit = 100)
|