Anash commited on
Commit
8d4500d
·
verified ·
1 Parent(s): a3607d9

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
+ faiss_index/index.faiss filter=lfs diff=lfs merge=lfs -text
Dockerfile ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use the latest Python image
2
+ FROM python:3.10.12
3
+
4
+ # Set the working directory to /app
5
+ WORKDIR /app
6
+
7
+ # Install system dependencies
8
+ RUN apt-get update && \
9
+ apt-get install -y swig && \
10
+ apt-get install -y libomp-dev
11
+
12
+ # Copy the current directory contents into the container at /app
13
+ COPY . /app
14
+
15
+ # Install any needed packages specified in requirements.txt
16
+ RUN pip install --no-cache-dir -r requirements.txt
17
+
18
+ # Make port 8501 available to the world outside this container
19
+ EXPOSE 8501
20
+
21
+ # Define environment variable
22
+ ENV NAME World
23
+
24
+ # Run streamlit when the container launches
25
+ CMD ["streamlit", "run", "pharmagpt.py"]
26
+
faiss_index/index.faiss ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e9f0c2b9428cdc6c37f62eba62518b5a56a1872999ec5485fe81f479099ffde0
3
+ size 19230765
faiss_index/index.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f51bbc4af3cdeaac50c127a920281d77737735a9a05c5578633a88c2e8fa74ae
3
+ size 63081007
pharmagpt.py ADDED
@@ -0,0 +1,181 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from langchain.vectorstores import FAISS
2
+ from langchain import PromptTemplate
3
+ import streamlit as st
4
+ import os
5
+ from langchain.chains import RetrievalQA
6
+ import time
7
+ from datetime import datetime
8
+ import pytz
9
+ from langchain_google_genai import GoogleGenerativeAIEmbeddings
10
+ import google.generativeai as genai
11
+ from langchain.vectorstores import FAISS
12
+ from langchain_google_genai import ChatGoogleGenerativeAI
13
+
14
+ os.environ["GOOGLE_API_KEY"] = "AIzaSyB9O6fAGbU0ptk5VirtkTrLfmMCmaZqFCA"
15
+
16
+ # Move this image display up
17
+ st.markdown(
18
+ '<div class = "center"> <img src = "https://solukraft.com/Home/Black%20BG%20PNG.png" style = "width : 100px;" alt = "Center Aligned Image"> </div>',
19
+ unsafe_allow_html=True,
20
+ )
21
+
22
+ st.markdown(
23
+ """ <style>
24
+ body {
25
+ background-size: cover;
26
+ }
27
+ .css-fg4pbf {
28
+ background:rgba(255,255,255,0.8) !important;
29
+ }
30
+ .css-18ni7ap {
31
+ background:none !important;
32
+ }
33
+ a.css-eczf16.e1nzilvr3 {
34
+ display: none;
35
+ }
36
+ .block-container {
37
+ padding: 2rem 0 10rem 0;
38
+ }
39
+ button[kind="primary"] {
40
+ position: fixed;
41
+ bottom: 8rem;
42
+ }
43
+
44
+ button[kind="secondary"] {
45
+ position: fixed;
46
+ bottom: 8rem;
47
+ transform: translateX(630px)
48
+ }
49
+ h1#private-bot-using-gpt-3-5 {
50
+ padding-top: 0;
51
+ }
52
+ .font {
53
+ font-size:22px ;
54
+ font-family: 'Segoe UI';
55
+ color:#B7D313;
56
+ font-weight:400;
57
+ text-align:center;
58
+ }
59
+ h1 {
60
+ font-size:30px ;
61
+ font-family: 'Segoe UI';
62
+ color:#002C84;
63
+ font-weight:bold;
64
+ text-align:center;
65
+ }
66
+ .center {
67
+ display: flex;
68
+ justify-content : center ;
69
+ }
70
+ </style> """,
71
+ unsafe_allow_html=True,
72
+ )
73
+
74
+ def get_conversational_chain():
75
+
76
+ prompt_template = """
77
+ Answer the question as detailed as possible from the provided context, make sure to provide all the details
78
+ Context:\n {context}?\n
79
+ Question: \n{question}\n
80
+
81
+ Answer:
82
+ """
83
+
84
+ model = ChatGoogleGenerativeAI(model="gemini-pro",
85
+ temperature=0.3)
86
+ embeddings = GoogleGenerativeAIEmbeddings(model = "models/embedding-001")
87
+
88
+ new_db = FAISS.load_local("", embeddings)
89
+ prompt = PromptTemplate(template = prompt_template, input_variables = ["context", "question"])
90
+ qa_chain = RetrievalQA.from_chain_type(llm=model,
91
+ chain_type='stuff',
92
+ retriever=new_db.as_retriever(search_kwargs={'k': 2}),
93
+ return_source_documents=True,
94
+ chain_type_kwargs={'prompt': prompt}
95
+ )
96
+ return qa_chain
97
+
98
+
99
+
100
+ def user_input(user_question):
101
+ chain = get_conversational_chain()
102
+ response = chain.invoke(user_question)
103
+ return response
104
+
105
+
106
+ st.title("SoluKraft PharmaGPT")
107
+
108
+ if "messages" not in st.session_state:
109
+ st.session_state.messages = []
110
+
111
+
112
+ # Display chat messages from history on app rerun
113
+ for message in st.session_state.messages:
114
+ with st.chat_message(message["role"]):
115
+ st.markdown(message["content"])
116
+ st.markdown(f"<div style='text-align: right'>{message['timestamp']}</div>", unsafe_allow_html=True)
117
+
118
+
119
+ if prompt := st.chat_input("send a message"):
120
+ # Display user message in chat message container
121
+ utc_now = datetime.utcnow()
122
+ # Convert UTC time to IST
123
+ ist_timezone = pytz.timezone('Asia/Kolkata')
124
+ current_time = utc_now.astimezone(ist_timezone).strftime("%Y-%m-%d %H:%M:%S")
125
+ with st.chat_message("user"):
126
+ st.markdown(prompt)
127
+ st.markdown(f"<div style='text-align: right'>{current_time}</div>", unsafe_allow_html=True,)
128
+
129
+ # Add user message to chat history with timestamp
130
+ st.session_state.messages.append({"role": "user", "content": prompt, "timestamp": current_time})
131
+
132
+ start_time = time.time()
133
+ response = user_input(prompt)
134
+ end_time = time.time()
135
+ utc_now = datetime.utcnow()
136
+ # Convert UTC time to IST
137
+ ist_timezone = pytz.timezone('Asia/Kolkata')
138
+ current_time = utc_now.astimezone(ist_timezone).strftime("%Y-%m-%d %H:%M:%S")
139
+ execution_time = end_time - start_time
140
+ #st.write(f"Execution time: {execution_time:.4f} seconds")
141
+
142
+ # Display assistant response in chat message container
143
+ with st.chat_message("assistant"):
144
+ st.markdown(response['result'])
145
+ st.markdown(f"<div style='text-align: right'>{current_time}</div>", unsafe_allow_html=True,)
146
+ st.session_state.messages.append({"role": "assistant", "content": response['result'], "timestamp": current_time})
147
+
148
+ if len(st.session_state.messages) != 0:
149
+ if st.button("Clear", type="primary"):
150
+ st.session_state.messages = []
151
+
152
+ if st.button("Regenerate", type="secondary"):
153
+ prompt = st.session_state.messages[0]['content']
154
+ utc_now = datetime.utcnow()
155
+
156
+ # Convert UTC time to IST
157
+ ist_timezone = pytz.timezone('Asia/Kolkata')
158
+ current_time = utc_now.astimezone(ist_timezone).strftime("%Y-%m-%d %H:%M:%S")
159
+ with st.chat_message("user"):
160
+ st.markdown(prompt)
161
+ st.markdown(f"<div style='text-align: right'>{current_time}</div>", unsafe_allow_html=True,)
162
+ # Add user message to chat history with timestamp
163
+ st.session_state.messages.append({"role": "user", "content": prompt, "timestamp": current_time})
164
+ start_time = time.time()
165
+ response = user_input(prompt)
166
+ end_time = time.time()
167
+ execution_time = end_time - start_time
168
+ st.write(f"Execution time: {execution_time:.4f} seconds")
169
+ with st.chat_message("assistant"):
170
+ st.markdown(response['result'])
171
+ utc_now = datetime.utcnow()
172
+
173
+ # Convert UTC time to IST
174
+ ist_timezone = pytz.timezone('Asia/Kolkata')
175
+ current_time = utc_now.astimezone(ist_timezone).strftime("%Y-%m-%d %H:%M:%S")
176
+ st.markdown(f"<div style='text-align: right'>{current_time}</div>", unsafe_allow_html=True,)
177
+
178
+ # Add assistant response to chat history with timestamp
179
+ st.session_state.messages.append({"role": "assistant", "content": response['result'], "timestamp": current_time,"metadata":response['source_documents']})
180
+
181
+
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ streamlit
2
+ langchain
3
+ faiss-cpu
4
+ langchain-google-genai