drkareemkamal commited on
Commit
21cc216
·
verified ·
1 Parent(s): 83da286

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -80
app.py DELETED
@@ -1,80 +0,0 @@
1
-
2
- # import libraries
3
- import os
4
- from dotenv import load_dotenv
5
-
6
- import pinecone
7
- from langchain.document_loaders import PyPDFDirectoryLoader
8
- from langchain.text_splitter import RecursiveCharacterTextSplitter
9
- from langchain.embeddings.openai import OpenAIEmbeddings
10
- from langchain_pinecone import PineconeVectorStore
11
- from langchain.prompts import PromptTemplate
12
- from langchain.chains.question_answering import load_qa_chain
13
- from ctransformers import CTransformers
14
-
15
- load_dotenv()
16
-
17
- embeddings = HuggingFaceBgeEmbeddings(model_name = 'sentence-transformers/all-MiniLM-L6-v2',
18
- model_kwargs = {'device':'cpu'})
19
-
20
- os.environ['PINECONE_API_KEY'] = 'afb0bb4d-3c15-461b-91a4-fb12fb1f25f2'
21
- index_name = 'harisonvecot'
22
-
23
- vectorstore = PineconeVectorStore(index_name=index_name,embedding=embeddings)
24
-
25
- # Create the vector index from documents
26
- def create_index(documents):
27
- vectorstore.add_documents(documents)
28
-
29
- # Retrieve query from Pinecone
30
- def retrieve_query(query, k=2):
31
- matching_results = vectorstore.similarity_search(query, k=k)
32
- return matching_results
33
-
34
- # Custom prompt template
35
- custom_prompt_template = '''
36
- use the following pieces of information to answer the user's questions.
37
- If you don't know the answer, please just say that you don't know the answer, don't try to make up an answer.
38
-
39
- Content : {context}
40
- Question : {question}
41
-
42
- only return the helpful answer below and nothing else.
43
- '''
44
-
45
- def set_custom_prompt():
46
- prompt = PromptTemplate(template=custom_prompt_template, input_variables=['context', 'question'])
47
- return prompt
48
-
49
- # Load LLM model
50
- llm_model = CTransformers(model_name='TheBloke/Llama-2-7B-Chat-GGML',
51
- model_type = 'llama',
52
- max_new_token = 512,
53
- temperature=0.5)
54
-
55
- # Create retrieval QA chain
56
- def retrieval_qa_chain():
57
- prompt = set_custom_prompt()
58
- chain = load_qa_chain(llm_model, chain_type='stuff', prompt=prompt)
59
- return chain
60
-
61
- # Search answers from Vector DB
62
- def retrieve_answer(query):
63
- doc_search = retrieve_query(query)
64
- chain = retrieval_qa_chain()
65
- response = chain.run(input_documents=doc_search, question=query)
66
- return response
67
-
68
- queries = st.text_input('write a medical questions ?')
69
- # Example usage
70
- submit = st.button('submit')
71
- # Read and process documents
72
- # doc = read_doc('documents/')
73
- # documents = chunk_data(docs=doc)
74
- # create_index(documents)
75
- if submit :
76
- if queries :
77
- # Query and get answer
78
- #our_query = 'What is cause of Eczema?'
79
- answer = retrieve_answer(queries)
80
- st.write(answer)