Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -7,6 +7,9 @@ from transformers import TFAutoModel, AutoTokenizer
|
|
7 |
import numpy as np
|
8 |
import pandas as pd
|
9 |
import faiss
|
|
|
|
|
|
|
10 |
|
11 |
try:
|
12 |
nlp = spacy.load("en_core_web_sm")
|
@@ -110,8 +113,6 @@ def extracted_query_embeddings(queries, max_length=64):
|
|
110 |
verbose=1)
|
111 |
return query_embeddings
|
112 |
|
113 |
-
#Wikipedia API:
|
114 |
-
|
115 |
def get_pagetext(page):
|
116 |
s = str(page).replace("/t","")
|
117 |
return s
|
@@ -119,3 +120,97 @@ def get_pagetext(page):
|
|
119 |
def get_wiki_summary(search):
|
120 |
wiki_wiki = wikipediaapi.Wikipedia('en')
|
121 |
page = wiki_wiki.page(search)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
import numpy as np
|
8 |
import pandas as pd
|
9 |
import faiss
|
10 |
+
import datetime
|
11 |
+
import time
|
12 |
+
|
13 |
|
14 |
try:
|
15 |
nlp = spacy.load("en_core_web_sm")
|
|
|
113 |
verbose=1)
|
114 |
return query_embeddings
|
115 |
|
|
|
|
|
116 |
def get_pagetext(page):
|
117 |
s = str(page).replace("/t","")
|
118 |
return s
|
|
|
120 |
def get_wiki_summary(search):
|
121 |
wiki_wiki = wikipediaapi.Wikipedia('en')
|
122 |
page = wiki_wiki.page(search)
|
123 |
+
|
124 |
+
|
125 |
+
def get_wiki_summaryDF(search):
|
126 |
+
wiki_wiki = wikipediaapi.Wikipedia('en')
|
127 |
+
page = wiki_wiki.page(search)
|
128 |
+
|
129 |
+
isExist = page.exists()
|
130 |
+
if not isExist:
|
131 |
+
return isExist, "Not found", "Not found", "Not found", "Not found"
|
132 |
+
|
133 |
+
pageurl = page.fullurl
|
134 |
+
pagetitle = page.title
|
135 |
+
pagesummary = page.summary[0:60]
|
136 |
+
pagetext = get_pagetext(page.text)
|
137 |
+
|
138 |
+
backlinks = page.backlinks
|
139 |
+
linklist = ""
|
140 |
+
for link in backlinks.items():
|
141 |
+
pui = link[0]
|
142 |
+
linklist += pui + " , "
|
143 |
+
a=1
|
144 |
+
|
145 |
+
categories = page.categories
|
146 |
+
categorylist = ""
|
147 |
+
for category in categories.items():
|
148 |
+
pui = category[0]
|
149 |
+
categorylist += pui + " , "
|
150 |
+
a=1
|
151 |
+
|
152 |
+
links = page.links
|
153 |
+
linklist2 = ""
|
154 |
+
for link in links.items():
|
155 |
+
pui = link[0]
|
156 |
+
linklist2 += pui + " , "
|
157 |
+
a=1
|
158 |
+
|
159 |
+
sections = page.sections
|
160 |
+
|
161 |
+
ex_dic = {
|
162 |
+
'Entity' : ["URL","Title","Summary", "Text", "Backlinks", "Links", "Categories"],
|
163 |
+
'Value': [pageurl, pagetitle, pagesummary, pagetext, linklist,linklist2, categorylist ]
|
164 |
+
}
|
165 |
+
|
166 |
+
df = pd.DataFrame(ex_dic)
|
167 |
+
|
168 |
+
return df
|
169 |
+
|
170 |
+
|
171 |
+
def save_message(name, message):
|
172 |
+
now = datetime.datetime.now()
|
173 |
+
timestamp = now.strftime("%Y-%m-%d %H:%M:%S")
|
174 |
+
with open("chat.txt", "a") as f:
|
175 |
+
f.write(f"{timestamp} - {name}: {message}\n")
|
176 |
+
|
177 |
+
def main():
|
178 |
+
st.title("Streamlit Chat")
|
179 |
+
|
180 |
+
name = st.text_input("Name")
|
181 |
+
message = st.text_input("Message")
|
182 |
+
if st.button("Submit"):
|
183 |
+
|
184 |
+
# wiki
|
185 |
+
df = get_wiki_summaryDF(message)
|
186 |
+
|
187 |
+
save_message(name, message)
|
188 |
+
save_message(name, df)
|
189 |
+
|
190 |
+
st.text("Message sent!")
|
191 |
+
|
192 |
+
|
193 |
+
st.text("Chat history:")
|
194 |
+
with open("chat.txt", "a+") as f:
|
195 |
+
f.seek(0)
|
196 |
+
chat_history = f.read()
|
197 |
+
st.text(chat_history)
|
198 |
+
|
199 |
+
countdown = st.empty()
|
200 |
+
t = 60
|
201 |
+
while t:
|
202 |
+
mins, secs = divmod(t, 60)
|
203 |
+
countdown.text(f"Time remaining: {mins:02d}:{secs:02d}")
|
204 |
+
time.sleep(1)
|
205 |
+
t -= 1
|
206 |
+
if t == 0:
|
207 |
+
countdown.text("Time's up!")
|
208 |
+
with open("chat.txt", "a+") as f:
|
209 |
+
f.seek(0)
|
210 |
+
chat_history = f.read()
|
211 |
+
st.text(chat_history)
|
212 |
+
t = 60
|
213 |
+
|
214 |
+
if __name__ == "__main__":
|
215 |
+
main()
|
216 |
+
|