vincentmin commited on
Commit
42c6b22
1 Parent(s): 99471f1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -3
app.py CHANGED
@@ -1,7 +1,6 @@
1
  import gradio as gr
2
  from datetime import datetime, timedelta
3
  import arxiv
4
- from langchain.text_splitter import RecursiveCharacterTextSplitter
5
  from langchain.vectorstores import Chroma
6
  from langchain.embeddings import HuggingFaceEmbeddings
7
  from langchain.llms import HuggingFaceHub
@@ -12,6 +11,7 @@ from langchain.schema import Document
12
 
13
  MAX_RESULTS = 100
14
  FORMAT = '%Y%m%d%H%M%S'
 
15
  embeddings = HuggingFaceEmbeddings()
16
 
17
  document_prompt = PromptTemplate(
@@ -74,14 +74,12 @@ def get_data(category: str, lookback_days: float, user_query: str):
74
  print("User query:", user_query)
75
 
76
  min_date, max_date = get_date_range(lookback_days)
77
- print(min_date, max_date)
78
  docs = get_documents(category, min_date, max_date)
79
  if len(docs) == 0:
80
  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.'."
81
  db = Chroma.from_documents(docs, embeddings)
82
  retriever = db.as_retriever()
83
  relevant_docs = retriever.get_relevant_documents(user_query)
84
- print(relevant_docs[0].metadata)
85
  articles = ""
86
  for doc in relevant_docs:
87
  articles += f"**Title: {doc.metadata['title']}**\n\nAuthors: {doc.metadata['authors']}\n\nAbstract: {doc.page_content}\n\nID: {doc.metadata['id']}\n\n"
 
1
  import gradio as gr
2
  from datetime import datetime, timedelta
3
  import arxiv
 
4
  from langchain.vectorstores import Chroma
5
  from langchain.embeddings import HuggingFaceEmbeddings
6
  from langchain.llms import HuggingFaceHub
 
11
 
12
  MAX_RESULTS = 100
13
  FORMAT = '%Y%m%d%H%M%S'
14
+
15
  embeddings = HuggingFaceEmbeddings()
16
 
17
  document_prompt = PromptTemplate(
 
74
  print("User query:", user_query)
75
 
76
  min_date, max_date = get_date_range(lookback_days)
 
77
  docs = get_documents(category, min_date, max_date)
78
  if len(docs) == 0:
79
  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.'."
80
  db = Chroma.from_documents(docs, embeddings)
81
  retriever = db.as_retriever()
82
  relevant_docs = retriever.get_relevant_documents(user_query)
 
83
  articles = ""
84
  for doc in relevant_docs:
85
  articles += f"**Title: {doc.metadata['title']}**\n\nAuthors: {doc.metadata['authors']}\n\nAbstract: {doc.page_content}\n\nID: {doc.metadata['id']}\n\n"