Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
import json
|
2 |
|
3 |
from langchain_community.retrievers import BM25Retriever
|
@@ -11,18 +12,18 @@ def load_docs_from_json(json_path):
|
|
11 |
|
12 |
docs = []
|
13 |
for paper in papers:
|
14 |
-
page_content = f"{paper['title']}\n\
|
15 |
doc = Document(
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
|
27 |
return docs
|
28 |
|
@@ -33,9 +34,13 @@ docs = load_docs_from_json(json_path)
|
|
33 |
retriever = BM25Retriever.from_documents(docs)
|
34 |
retriever.k = 10
|
35 |
|
|
|
|
|
|
|
|
|
36 |
# streamlit
|
37 |
st.title("HF Daily Papers Search")
|
38 |
-
st.markdown(f"Search papers from [HF daily papers](https://huggingface.co/papers).\nNmber of documents: {len(docs)}")
|
39 |
|
40 |
user_query = st.text_input("Search anything...")
|
41 |
if st.button('β'):
|
|
|
1 |
+
import datetime
|
2 |
import json
|
3 |
|
4 |
from langchain_community.retrievers import BM25Retriever
|
|
|
12 |
|
13 |
docs = []
|
14 |
for paper in papers:
|
15 |
+
page_content = f"Title: {paper['title']}\n\nAbstract: {paper['abstract']}"
|
16 |
doc = Document(
|
17 |
+
page_content=page_content,
|
18 |
+
metadata={
|
19 |
+
'title': paper['title'],
|
20 |
+
'link': paper['link'],
|
21 |
+
'authors': paper['authors'],
|
22 |
+
'submitter': paper['submitter'],
|
23 |
+
'date': paper['date'],
|
24 |
+
}
|
25 |
+
)
|
26 |
+
docs.append(doc)
|
27 |
|
28 |
return docs
|
29 |
|
|
|
34 |
retriever = BM25Retriever.from_documents(docs)
|
35 |
retriever.k = 10
|
36 |
|
37 |
+
dates = [datetime.datetime.strptime(doc.metadata['date'], '%Y-%m-%d') for doc in docs]
|
38 |
+
oldest_date = min(dates)
|
39 |
+
newest_date = max(dates)
|
40 |
+
|
41 |
# streamlit
|
42 |
st.title("HF Daily Papers Search")
|
43 |
+
st.markdown(f"Search papers from [HF daily papers](https://huggingface.co/papers).\nNmber of documents: {len(docs)}\nfrom {oldest_date.strftime('%Y-%m-%d')} to {newest_date.strftime('%Y-%m-%d')}")
|
44 |
|
45 |
user_query = st.text_input("Search anything...")
|
46 |
if st.button('β'):
|