vincentmin commited on
Commit
6e36ec1
·
1 Parent(s): 93f881f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -6
app.py CHANGED
@@ -19,14 +19,14 @@ document_prompt = PromptTemplate(
19
  input_variables=["page_content", "Title"],
20
  )
21
  prompt = PromptTemplate(
22
- template="""Write a personalised newsletter for a researcher on the most recent exciting developments in his field. The researcher describes his work as follows:"{context}". Base the newsletter on the articles below. Extract the most exciting points and combine them into an excillerating newsletter. Use Markdown format\n#ARTICLES\n\n"{text}"\n\nNEWSLETTER:\n# Your AI curated newsletter\n""",
23
  input_variables=["context", "text"])
24
 
25
  REPO_ID = "HuggingFaceH4/starchat-beta"
26
  llm = HuggingFaceHub(
27
  repo_id=REPO_ID,
28
  model_kwargs={
29
- "max_new_tokens": 300,
30
  "do_sample": True,
31
  "temperature": 0.8,
32
  "top_p": 0.9
@@ -52,19 +52,18 @@ def get_data(lookback_days: float, user_query: str):
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 = loader.load()
56
- docs = [process_document(doc) for doc in docs]
57
  db = Chroma.from_documents(docs, embeddings)
58
  retriever = db.as_retriever()
59
  relevant_docs = retriever.get_relevant_documents(user_query)
60
  print(relevant_docs[0].metadata)
61
  articles = ""
62
  for doc in relevant_docs:
63
- articles += f"**Title: {doc.metadata['Title']}**\n\nAbstract: {doc.metadata['Summary']}\n\n"
64
  output = stuff_chain({"input_documents": relevant_docs, "context": user_query})
65
  output_text = output["output_text"].split("<|end|>")[0]
66
  print("LLM output:", output_text)
67
- return f"# Your AI curated newsletter\n{output['output_text']}\n\n\n\n## Used articles:\n\n{articles}"
68
 
69
  with gr.Blocks() as demo:
70
  gr.Markdown(
 
19
  input_variables=["page_content", "Title"],
20
  )
21
  prompt = PromptTemplate(
22
+ template="""Write an engaging newsletter on the most recent exciting developments in the following field:"{context}". Base the newsletter on the articles below. Extract the most exciting points and combine them into an excillerating newsletter. Use emojis to catch attention and use the Markdown format.\n\n#ARTICLES\n"{text}"\n\nNEWSLETTER:\n# AI curated newsletter\n""",
23
  input_variables=["context", "text"])
24
 
25
  REPO_ID = "HuggingFaceH4/starchat-beta"
26
  llm = HuggingFaceHub(
27
  repo_id=REPO_ID,
28
  model_kwargs={
29
+ "max_new_tokens": 400,
30
  "do_sample": True,
31
  "temperature": 0.8,
32
  "top_p": 0.9
 
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
  db = Chroma.from_documents(docs, embeddings)
57
  retriever = db.as_retriever()
58
  relevant_docs = retriever.get_relevant_documents(user_query)
59
  print(relevant_docs[0].metadata)
60
  articles = ""
61
  for doc in relevant_docs:
62
+ articles += f"**Title: {doc.metadata['Title']}**\n\nAuthors: {doc.metadata['Authors']}\n\nAbstract: {doc.metadata['Summary']}\n\n"
63
  output = stuff_chain({"input_documents": relevant_docs, "context": user_query})
64
  output_text = output["output_text"].split("<|end|>")[0]
65
  print("LLM output:", output_text)
66
+ return f"# Your AI curated newsletter\n{output_text}\n\n\n\n## Filtered {len(docs)} articles down to the following relevant articles:\n\n{articles}"
67
 
68
  with gr.Blocks() as demo:
69
  gr.Markdown(