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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -16
app.py CHANGED
@@ -5,15 +5,12 @@ from langchain.text_splitter import RecursiveCharacterTextSplitter
5
  from langchain.vectorstores import Chroma
6
  from langchain.embeddings import HuggingFaceEmbeddings
7
  from langchain.llms import HuggingFaceHub
8
- # from langchain.llms import FakeListLLM
9
  from langchain.chains import LLMChain, StuffDocumentsChain
10
  from langchain.prompts import PromptTemplate
11
  from langchain.schema import Document
12
 
13
 
14
  LOAD_MAX_DOCS = 100
15
- # CHUNK_SIZE = 1000
16
- # text_splitter = RecursiveCharacterTextSplitter(chunk_size=CHUNK_SIZE)
17
 
18
  embeddings = HuggingFaceEmbeddings()
19
 
@@ -25,7 +22,6 @@ prompt = PromptTemplate(
25
  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""",
26
  input_variables=["context", "text"])
27
 
28
- # llm = FakeListLLM(responses=list(map(str, range(100))))
29
  REPO_ID = "HuggingFaceH4/starchat-beta"
30
  llm = HuggingFaceHub(
31
  repo_id=REPO_ID,
@@ -53,7 +49,7 @@ def process_document(doc: Document):
53
  def get_data(lookback_days: float, user_query: str):
54
  print("User query:", user_query)
55
  max_date = date.today()
56
- min_date = (max_date - timedelta(days=3)).strftime('%Y%m%d')
57
  query = f"cat:hep-th AND submittedDate:[{min_date.strftime('%Y%m%d')} TO {max_date.strftime('%Y%m%d')}]"
58
  loader = ArxivLoader(query=query, load_max_docs=LOAD_MAX_DOCS)
59
  docs = loader.load()
@@ -70,14 +66,6 @@ def get_data(lookback_days: float, user_query: str):
70
  print("LLM output:", output_text)
71
  return f"# Your AI curated newsletter\n{output['output_text']}\n\n\n\n## Used articles:\n\n{articles}"
72
 
73
- # demo = gr.Interface(
74
- # fn=get_data,
75
- # inputs=[lookback_days, input_text]
76
- # outputs=gr.Markdown(),
77
- # title="Arxiv AI Curated Newsletter",
78
- # description="Describe your field of research in a few words to get a newsletter-style summary of today's Arxiv articles.",
79
- # )
80
-
81
  with gr.Blocks() as demo:
82
  gr.Markdown(
83
  """
@@ -87,14 +75,17 @@ with gr.Blocks() as demo:
87
  Get a newsletter-style summary of today's Arxiv articles personalised to your field of research.
88
  """
89
  )
90
- lookback_days = gr.Number(2, label="Articles from this many days in the past will be searched through.", minimum=1, maximum=7)
 
 
 
91
  input_text = gr.Textbox(placeholder="Describe your field of research in a few words")
92
  gr.Examples(
93
  [["Supersymmetric Conformal Field Theory"], ["Black hole information paradox"]],
94
  input_text,
95
  )
96
  output = gr.Markdown()
97
-
98
- input_text.change(fn=get_data, inputs=[lookback_days,input_text], outputs=output)
99
 
100
  demo.queue().launch()
 
5
  from langchain.vectorstores import Chroma
6
  from langchain.embeddings import HuggingFaceEmbeddings
7
  from langchain.llms import HuggingFaceHub
 
8
  from langchain.chains import LLMChain, StuffDocumentsChain
9
  from langchain.prompts import PromptTemplate
10
  from langchain.schema import Document
11
 
12
 
13
  LOAD_MAX_DOCS = 100
 
 
14
 
15
  embeddings = HuggingFaceEmbeddings()
16
 
 
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,
 
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 = loader.load()
 
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(
71
  """
 
75
  Get a newsletter-style summary of today's Arxiv articles personalised to your field of research.
76
  """
77
  )
78
+
79
+ with gr.Accordion("Parameters", open=False):
80
+ lookback_days = gr.Number(2, label="Articles from this many days in the past will be searched through.", minimum=1, maximum=7)
81
+
82
  input_text = gr.Textbox(placeholder="Describe your field of research in a few words")
83
  gr.Examples(
84
  [["Supersymmetric Conformal Field Theory"], ["Black hole information paradox"]],
85
  input_text,
86
  )
87
  output = gr.Markdown()
88
+ btn = gr.Button(value="Submit")
89
+ btn.click(fn=get_data, inputs=[lookback_days,input_text], outputs=output)
90
 
91
  demo.queue().launch()