Spaces:
Sleeping
Sleeping
Commit
·
742e3f8
1
Parent(s):
4eb428c
Update app.py
Browse files
app.py
CHANGED
@@ -1,30 +1,28 @@
|
|
1 |
import arxiv
|
2 |
import gradio as gr
|
3 |
-
from
|
4 |
-
|
|
|
|
|
|
|
|
|
5 |
from langchain.llms import HuggingFaceHub
|
6 |
-
from
|
7 |
-
from langchain.vectorstores import Chroma
|
8 |
-
from langchain.chains import RetrievalQA
|
9 |
|
10 |
-
repo_id = '
|
11 |
-
client = arxiv.Client()
|
12 |
|
13 |
def loading_paper(): return 'Loading...'
|
14 |
|
15 |
def paper_changes(paper_id):
|
16 |
paper = next(arxiv.Client().results(arxiv.Search(id_list=[paper_id])))
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
global qa
|
26 |
-
qa = RetrievalQA.from_chain_type(llm=llm, chain_type='stuff', retriever=retriever, return_source_documents=True)
|
27 |
-
return 'Ready!!'
|
28 |
|
29 |
def add_text(history, text):
|
30 |
history = history + [(text, None)]
|
@@ -32,12 +30,12 @@ def add_text(history, text):
|
|
32 |
|
33 |
def bot(history):
|
34 |
response = infer(history[-1][0])
|
35 |
-
history[-1][1] = response
|
36 |
return history
|
37 |
|
38 |
def infer(question):
|
39 |
-
|
40 |
-
return
|
41 |
|
42 |
with gr.Blocks(theme='WeixuanYuan/Soft_dark') as demo:
|
43 |
with gr.Column():
|
|
|
1 |
import arxiv
|
2 |
import gradio as gr
|
3 |
+
from llama_index import (
|
4 |
+
VectorStoreIndex,
|
5 |
+
ServiceContext,
|
6 |
+
SimpleDirectoryReader,
|
7 |
+
Document
|
8 |
+
)
|
9 |
from langchain.llms import HuggingFaceHub
|
10 |
+
from llama_index.llms import LangChainLLM
|
|
|
|
|
11 |
|
12 |
+
repo_id = 'HuggingFaceH4/zephyr-7b-beta'
|
|
|
13 |
|
14 |
def loading_paper(): return 'Loading...'
|
15 |
|
16 |
def paper_changes(paper_id):
|
17 |
paper = next(arxiv.Client().results(arxiv.Search(id_list=[paper_id])))
|
18 |
+
docs = SimpleDirectoryReader(input_files=[paper.download_pdf()]).load_data()
|
19 |
+
doc = Document(text='\n\n'.join([doc.text for doc in docs]))
|
20 |
+
llm = LangChainLLM(llm=HuggingFaceHub(repo_id=repo_id, model_kwargs={'temperature': 0.3}))
|
21 |
+
service_context = ServiceContext.from_defaults(llm=llm, embed_model="local:BAAI/bge-small-en-v1.5")
|
22 |
+
index = VectorStoreIndex.from_documents([doc], service_context=service_context)
|
23 |
+
global query_engine
|
24 |
+
query_engine = index.as_query_engine()
|
25 |
+
return 'Ready!!!'
|
|
|
|
|
|
|
26 |
|
27 |
def add_text(history, text):
|
28 |
history = history + [(text, None)]
|
|
|
30 |
|
31 |
def bot(history):
|
32 |
response = infer(history[-1][0])
|
33 |
+
history[-1][1] = response
|
34 |
return history
|
35 |
|
36 |
def infer(question):
|
37 |
+
response = query_engine.query(question)
|
38 |
+
return response
|
39 |
|
40 |
with gr.Blocks(theme='WeixuanYuan/Soft_dark') as demo:
|
41 |
with gr.Column():
|