yutohub commited on
Commit
b9f0901
β€’
1 Parent(s): e9a9f19

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -12
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\n{paper['abstract']}"
15
  doc = Document(
16
- page_content=page_content,
17
- metadata={
18
- 'title': paper['title'],
19
- 'link': paper['link'],
20
- 'authors': paper['authors'],
21
- 'submitter': paper['submitter'],
22
- 'date': paper['date'],
23
- }
24
- )
25
- docs.append(doc)
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('β†’'):