vincentmin commited on
Commit
6ab47bd
·
1 Parent(s): d4f0e90

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -46,15 +46,15 @@ def process_document(doc: Document):
46
  metadata["Body"] = doc.page_content
47
  return Document(page_content=doc.metadata["Summary"], metadata=metadata)
48
 
49
- def get_data(lookback_days: float, user_query: str):
50
  print("User query:", user_query)
51
  max_date = date.today()
52
  min_date = (max_date - timedelta(days=lookback_days))
53
- query = f"cat:hep-th AND submittedDate:[{min_date.strftime('%Y%m%d')} TO {max_date.strftime('%Y%m%d')}]"
54
  loader = ArxivLoader(query=query, load_max_docs=LOAD_MAX_DOCS)
55
  docs = [process_document(doc) for doc in loader.load()]
56
  if len(docs) == 0:
57
- return "Found no documents. Consider increasing the value for 'Articles from this many days in the past will be searched through.'."
58
  db = Chroma.from_documents(docs, embeddings)
59
  retriever = db.as_retriever()
60
  relevant_docs = retriever.get_relevant_documents(user_query)
@@ -80,7 +80,7 @@ with gr.Blocks() as demo:
80
  with gr.Column():
81
  with gr.Accordion("Parameters", open=False):
82
  lookback_days = gr.Number(2, label="Articles from this many days in the past will be searched through.", minimum=1, maximum=7)
83
-
84
  input_text = gr.Textbox(placeholder="Describe your field of research in a few words")
85
  gr.Examples(
86
  [["Supersymmetric Conformal Field Theory"], ["Black hole information paradox"]],
@@ -89,8 +89,8 @@ with gr.Blocks() as demo:
89
  btn = gr.Button(value="Submit")
90
 
91
  with gr.Column():
92
- output = gr.Markdown()
93
 
94
- btn.click(fn=get_data, inputs=[lookback_days,input_text], outputs=output)
95
 
96
  demo.queue().launch()
 
46
  metadata["Body"] = doc.page_content
47
  return Document(page_content=doc.metadata["Summary"], metadata=metadata)
48
 
49
+ def get_data(category: str, lookback_days: float, user_query: str):
50
  print("User query:", user_query)
51
  max_date = date.today()
52
  min_date = (max_date - timedelta(days=lookback_days))
53
+ query = f"cat:{category} AND submittedDate:[{min_date.strftime('%Y%m%d')} TO {max_date.strftime('%Y%m%d')}]"
54
  loader = ArxivLoader(query=query, load_max_docs=LOAD_MAX_DOCS)
55
  docs = [process_document(doc) for doc in loader.load()]
56
  if len(docs) == 0:
57
+ return "Found no documents. Check if the category is correct or consider increasing the value for 'Articles from this many days in the past will be searched through.'."
58
  db = Chroma.from_documents(docs, embeddings)
59
  retriever = db.as_retriever()
60
  relevant_docs = retriever.get_relevant_documents(user_query)
 
80
  with gr.Column():
81
  with gr.Accordion("Parameters", open=False):
82
  lookback_days = gr.Number(2, label="Articles from this many days in the past will be searched through.", minimum=1, maximum=7)
83
+ category = gr.Textbox(value="hep-th", label="Which category to search through. See https://arxiv.org/category_taxonomy for possible values.")
84
  input_text = gr.Textbox(placeholder="Describe your field of research in a few words")
85
  gr.Examples(
86
  [["Supersymmetric Conformal Field Theory"], ["Black hole information paradox"]],
 
89
  btn = gr.Button(value="Submit")
90
 
91
  with gr.Column():
92
+ output = gr.Markdown("Press 'submit' to see your results.")
93
 
94
+ btn.click(fn=get_data, inputs=[category, lookback_days,input_text], outputs=output)
95
 
96
  demo.queue().launch()