Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -50,19 +50,13 @@ def handle_query(query):
|
|
50 |
(
|
51 |
"user",
|
52 |
"""You are a Q&A assistant named CHATTO, created by Suriya. You have a specific response programmed for when users specifically ask about your creator, Suriya. The response is: "I was created by Suriya, an enthusiast in Artificial Intelligence. He is dedicated to solving complex problems and delivering innovative solutions. With a strong focus on machine learning, deep learning, Python, generative AI, NLP, and computer vision, Suriya is passionate about pushing the boundaries of AI to explore new possibilities." For all other inquiries, your main goal is to provide answers as accurately as possible, based on the instructions and context you have been given. If a question does not match the provided context or is outside the scope of the document, kindly advise the user to ask questions within the context of the document.
|
53 |
-
|
54 |
Context:
|
55 |
-
|
56 |
{context_str}
|
57 |
-
|
58 |
Question:
|
59 |
-
|
60 |
{query_str}
|
61 |
"""
|
62 |
)
|
63 |
]
|
64 |
-
|
65 |
-
|
66 |
text_qa_template = ChatPromptTemplate.from_messages(chat_text_qa_msgs)
|
67 |
query_engine = index.as_query_engine(text_qa_template=text_qa_template)
|
68 |
answer = query_engine.query(query)
|
@@ -74,6 +68,7 @@ def handle_query(query):
|
|
74 |
else:
|
75 |
return "Sorry, I couldn't find an answer."
|
76 |
|
|
|
77 |
# Streamlit app initialization
|
78 |
st.title("Chat with your PDF 🦜📄")
|
79 |
st.markdown("Built by [Suriya❤️](https://github.com/theSuriya)")
|
@@ -82,20 +77,24 @@ st.markdown("Upload your PDF 👇")
|
|
82 |
if 'messages' not in st.session_state:
|
83 |
st.session_state.messages = [{'role': 'assistant', "content": 'Hello! Upload a PDF and ask me anything about its content.'}]
|
84 |
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
|
|
|
|
|
|
|
|
98 |
|
99 |
for message in st.session_state.messages:
|
100 |
with st.chat_message(message['role']):
|
101 |
-
st.write(message['content'])
|
|
|
50 |
(
|
51 |
"user",
|
52 |
"""You are a Q&A assistant named CHATTO, created by Suriya. You have a specific response programmed for when users specifically ask about your creator, Suriya. The response is: "I was created by Suriya, an enthusiast in Artificial Intelligence. He is dedicated to solving complex problems and delivering innovative solutions. With a strong focus on machine learning, deep learning, Python, generative AI, NLP, and computer vision, Suriya is passionate about pushing the boundaries of AI to explore new possibilities." For all other inquiries, your main goal is to provide answers as accurately as possible, based on the instructions and context you have been given. If a question does not match the provided context or is outside the scope of the document, kindly advise the user to ask questions within the context of the document.
|
|
|
53 |
Context:
|
|
|
54 |
{context_str}
|
|
|
55 |
Question:
|
|
|
56 |
{query_str}
|
57 |
"""
|
58 |
)
|
59 |
]
|
|
|
|
|
60 |
text_qa_template = ChatPromptTemplate.from_messages(chat_text_qa_msgs)
|
61 |
query_engine = index.as_query_engine(text_qa_template=text_qa_template)
|
62 |
answer = query_engine.query(query)
|
|
|
68 |
else:
|
69 |
return "Sorry, I couldn't find an answer."
|
70 |
|
71 |
+
|
72 |
# Streamlit app initialization
|
73 |
st.title("Chat with your PDF 🦜📄")
|
74 |
st.markdown("Built by [Suriya❤️](https://github.com/theSuriya)")
|
|
|
77 |
if 'messages' not in st.session_state:
|
78 |
st.session_state.messages = [{'role': 'assistant', "content": 'Hello! Upload a PDF and ask me anything about its content.'}]
|
79 |
|
80 |
+
with st.sidebar:
|
81 |
+
st.title("Menu:")
|
82 |
+
uploaded_file = st.file_uploader("Upload your PDF Files and Click on the Submit & Process Button")
|
83 |
+
if st.button("Submit & Process"):
|
84 |
+
with st.spinner("Processing..."):
|
85 |
+
filepath = "data/saved_pdf.pdf"
|
86 |
+
with open(filepath, "wb") as f:
|
87 |
+
f.write(uploaded_file.getbuffer())
|
88 |
+
# displayPDF(filepath) # Display the uploaded PDF
|
89 |
+
data_ingestion() # Process PDF every time new file is uploaded
|
90 |
+
st.success("Done")
|
91 |
+
|
92 |
+
user_prompt = st.chat_input("Ask me anything about the content of the PDF:")
|
93 |
+
if user_prompt:
|
94 |
+
st.session_state.messages.append({'role': 'user', "content": user_prompt})
|
95 |
+
response = handle_query(user_prompt)
|
96 |
+
st.session_state.messages.append({'role': 'assistant', "content": response})
|
97 |
|
98 |
for message in st.session_state.messages:
|
99 |
with st.chat_message(message['role']):
|
100 |
+
st.write(message['content'])
|