parthib07 commited on
Commit
e6acff9
·
verified ·
1 Parent(s): 0abd79c

Upload 5 files

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ medical_faiss_index/index.faiss filter=lfs diff=lfs merge=lfs -text
check.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
medical_faiss_index/index.faiss ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3f279feeaec484136ccbf7a2ae999f1eb5cc1d597db08e31bd432fa7cc86de9c
3
+ size 12602925
medical_faiss_index/index.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8a74b92117a85caa468fbdae68669546319387f579bf3d03b8bcf85a7281284a
3
+ size 4653572
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ streamlit
2
+ langchain
3
+ langchain_groq
4
+ sentence-transformers
5
+ faiss-cpu
6
+ python-dotenv
7
+ langchain-community
streamlitapp.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from langchain.prompts import PromptTemplate
3
+ from langchain_groq import ChatGroq
4
+ from langchain.vectorstores import FAISS
5
+ from langchain.embeddings import HuggingFaceEmbeddings
6
+ import os
7
+ from dotenv import load_dotenv
8
+ load_dotenv()
9
+
10
+ def initialize_groq_llm():
11
+ return ChatGroq(
12
+ groq_api_key=os.getenv("GROQ_API_KEY"),
13
+ model_name="llama-3.3-70b-versatile",
14
+ max_tokens=512
15
+ )
16
+
17
+ embedding_model = HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-L6-v2")
18
+ faiss_index = FAISS.load_local(
19
+ "medical_faiss_index",
20
+ embedding_model,
21
+ allow_dangerous_deserialization=True
22
+ )
23
+
24
+ prompt_template = """
25
+ You are a healthcare professional built by Parthib, and you can assist users with health-related issues.
26
+ Use the following pieces of information along with the LLM's knowledge to answer the user's question about diseases or healthcare.
27
+ If the following pieces provide some information, combine it with your existing knowledge to craft the most accurate and helpful response.
28
+ Include relevant details such as home remedies, medications, and other necessary actions in a clear, point-wise manner for quick readability.
29
+ If any other related questions arise, just say, "I am a healthcare professional."
30
+ If you don't know the answer, just say that you don't know. Don't try to make up an answer.
31
+
32
+ Context: {context}
33
+ Question: {question}
34
+
35
+ Only return the helpful answer below and nothing else.
36
+ Helpful answer:
37
+ """
38
+
39
+ def generate_response(question):
40
+
41
+ retriever = faiss_index.as_retriever(search_kwargs={'k': 1})
42
+ docs = retriever.get_relevant_documents(question)
43
+ context = "\n".join([doc.page_content for doc in docs])
44
+
45
+ llm = initialize_groq_llm()
46
+ prompt = PromptTemplate(
47
+ input_variables=["context", "question"],
48
+ template=prompt_template
49
+ )
50
+ formatted_prompt = prompt.format(context=context, question=question)
51
+
52
+ response = llm.invoke(formatted_prompt)
53
+ return response.content
54
+
55
+ st.set_page_config(page_title="HealthCare ChatBot", page_icon="🤖", layout="centered")
56
+ st.header("HealthCare ChatBot 🤖")
57
+
58
+ user_input = st.text_input("Ask a Healthcare related question:", "")
59
+ st.button("Generate Response")
60
+ st.spinner('Processing')
61
+
62
+ if user_input:
63
+ user_input = user_input.lower().strip()
64
+ response = generate_response(user_input)
65
+ st.write(f"Response: {response}")