-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
47 lines (41 loc) · 1.52 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from langchain.vectorstores import Qdrant
from langchain.embeddings import OpenAIEmbeddings
from langchain.llms.openai import OpenAI
from langchain.text_splitter import RecursiveCharacterTextSplitter
import streamlit as st
from dotenv import load_dotenv
from design import bot_template , user_template ,css
import qdrant_client
from langchain.chains import RetrievalQA
import os
def get_vector_store():
embedding = OpenAIEmbeddings()
client = qdrant_client.QdrantClient(
os.getenv("QDRANT_HOST"),
api_key=os.getenv('QDRANT_API_KEY')
)
vector_store = Qdrant(
client=client,
collection_name=os.getenv("QDRANT_COLLECTION_NAME"),
embeddings=embedding
)
return vector_store
def main():
load_dotenv()
st.set_page_config(page_title= "5th Sem Sol" , page_icon=":books:")
st.header(":green[Ask your problem from any subject] :books:")
st.write(css , unsafe_allow_html=True)
vector_store= get_vector_store()
qa= RetrievalQA.from_chain_type(
llm = OpenAI(),
chain_type="stuff" ,
retriever=vector_store.as_retriever()
)
user_input = st.text_input(":green[Please enter your question]")
if user_input:
st.write(user_template.replace("{{MSG}}", user_input), unsafe_allow_html=True)
with st.spinner("Getting response"):
reponse = qa.run(user_input)
st.write(bot_template.replace("{{MSG}}", reponse), unsafe_allow_html=True)
if __name__ == "__main__":
main()