Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
from huggingface_hub import hf_hub_download
|
| 3 |
+
|
| 4 |
+
model_name_or_path = "hlhr202/llama-7B-ggml-int4"
|
| 5 |
+
model_basename = "ggml-model-q4_0.bin" # the model is in bin format
|
| 6 |
+
|
| 7 |
+
model_path = hf_hub_download(repo_id=model_name_or_path, filename=model_basename)
|
| 8 |
+
|
| 9 |
+
n_gpu_layers = 40 # Change this value based on your model and your GPU VRAM pool.
|
| 10 |
+
n_batch = 256
|
| 11 |
+
|
| 12 |
+
import paperscraper
|
| 13 |
+
from paperqa import Docs
|
| 14 |
+
from langchain.llms import LlamaCpp
|
| 15 |
+
from langchain import PromptTemplate, LLMChain
|
| 16 |
+
from langchain.callbacks.manager import CallbackManager
|
| 17 |
+
from langchain.embeddings import LlamaCppEmbeddings
|
| 18 |
+
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
|
| 19 |
+
|
| 20 |
+
# Make sure the model path is correct for your system!
|
| 21 |
+
llm = LlamaCpp(
|
| 22 |
+
model_path="./ggml-model-q4_0.bin", callbacks=[StreamingStdOutCallbackHandler()]
|
| 23 |
+
)
|
| 24 |
+
embeddings = LlamaCppEmbeddings(model_path="./ggml-model-q4_0.bin")
|
| 25 |
+
|
| 26 |
+
docs = Docs(llm=llm, embeddings=embeddings)
|
| 27 |
+
|
| 28 |
+
keyword_search = 'bispecific antibody manufacture'
|
| 29 |
+
papers = paperscraper.search_papers(keyword_search, limit=2)
|
| 30 |
+
for path,data in papers.items():
|
| 31 |
+
try:
|
| 32 |
+
docs.add(path,chunk_chars=500)
|
| 33 |
+
except ValueError as e:
|
| 34 |
+
print('Could not read', path, e)
|
| 35 |
+
|
| 36 |
+
answer = docs.query("What manufacturing challenges are unique to bispecific antibodies?")
|
| 37 |
+
print(answer)
|
| 38 |
+
|
| 39 |
+
def re(r):
|
| 40 |
+
|
| 41 |
+
print(answer)
|
| 42 |
+
return r
|
| 43 |
+
|
| 44 |
+
gr.Interface(fn=re,inputs=gr.Textbox(),outputs=gr.Textbox).launch()
|