Initial commit.
Browse files- app.py +36 -4
- rdna3.txt +0 -0
- requirements.txt +3 -0
app.py
CHANGED
@@ -1,7 +1,39 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
-
def greet(name):
|
4 |
-
return "Hello " + name + "!!"
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from langchain import HuggingFaceHub
|
3 |
+
from langchain.chains.question_answering import load_qa_chain
|
4 |
+
from langchain.document_loaders import PyMuPDFLoader, TextLoader
|
5 |
+
from langchain.embeddings import HuggingFaceEmbeddings
|
6 |
+
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
7 |
+
from langchain.vectorstores import FAISS
|
8 |
+
from timeit import default_timer as timer
|
9 |
|
|
|
|
|
10 |
|
11 |
+
loader = TextLoader("rdna3.txt")
|
12 |
+
documents = loader.load()
|
13 |
+
|
14 |
+
splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=50)
|
15 |
+
chunks = splitter.split_documents(documents)
|
16 |
+
|
17 |
+
embeddings = HuggingFaceEmbeddings()
|
18 |
+
db = FAISS.from_documents(chunks, embeddings)
|
19 |
+
|
20 |
+
llm = HuggingFaceHub(
|
21 |
+
repo_id='google/flan-t5-base',
|
22 |
+
model_kwargs={"temperature": 0, "max_length": 128})
|
23 |
+
chain = load_qa_chain(llm, chain_type="stuff")
|
24 |
+
|
25 |
+
def ask(question):
|
26 |
+
answers = db.similarity_search(question, k=4)
|
27 |
+
result = chain.run(input_documents=answers, question=question)
|
28 |
+
return result
|
29 |
+
|
30 |
+
# Warm up.
|
31 |
+
ask("What is VGPR")
|
32 |
+
|
33 |
+
iface = gr.Interface(
|
34 |
+
fn=ask,
|
35 |
+
inputs=gr.Textbox(label="Question", placeholder="What is..."),
|
36 |
+
outputs=gr.Textbox(label="Answer"),
|
37 |
+
allow_flagging=False)
|
38 |
+
|
39 |
+
iface.launch(share=True)
|
rdna3.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
langchain
|
2 |
+
faiss-cpu
|
3 |
+
sentence_transformers
|