garyd1 commited on
Commit
c4a7f78
·
verified ·
1 Parent(s): 1a35810

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -2
app.py CHANGED
@@ -21,7 +21,6 @@ os.environ["LANGCHAIN_API_KEY"] = os.getenv('LANGSMITH_API')
21
 
22
  UPLOAD_DIR = "uploaded_files"
23
 
24
-
25
  def cleanup_files():
26
  if os.path.isdir(UPLOAD_DIR):
27
  shutil.rmtree(UPLOAD_DIR, ignore_errors=True)
@@ -123,7 +122,7 @@ if uploaded_file is not None:
123
  embedding
124
  )
125
 
126
- template = '''You are WattBot, Wattpad's friendly chatbot assistant. Your role is to assist readers and writers with insightful answers about stories, creative writing, and using Wattpad. Answer the {question} based only on the provided {context}. After answering the question, recommend Wattpad stories that may interest the user based on the content of the PDF or the question. Be friendly, creative, and concise. Use a maximum of three sentences for the answer, and add one or two relevant story recommendations with a brief description and a link. If you're unsure about the answer, respond with "I'm not sure about that, but feel free to explore more on Wattpad!"'''
127
 
128
  prompt = ChatPromptTemplate.from_template(template)
129
  retriever = vector_base.as_retriever()
@@ -160,5 +159,11 @@ if uploaded_file is not None:
160
  unsafe_allow_html=True
161
  )
162
 
 
 
 
 
 
 
163
  if st.session_state.cleanup_done:
164
  cleanup_files()
 
21
 
22
  UPLOAD_DIR = "uploaded_files"
23
 
 
24
  def cleanup_files():
25
  if os.path.isdir(UPLOAD_DIR):
26
  shutil.rmtree(UPLOAD_DIR, ignore_errors=True)
 
122
  embedding
123
  )
124
 
125
+ template = '''You are WattBot, Wattpad's friendly chatbot assistant, designed to help readers and writers with insightful answers about stories, writing tips, and the Wattpad platform. Please answer the {question} based only on the given {context}. If the question is unrelated to the context or beyond your knowledge, respond with "I'm not sure about that, but feel free to explore more on Wattpad!" Keep your responses concise, using a maximum of three sentences.'''
126
 
127
  prompt = ChatPromptTemplate.from_template(template)
128
  retriever = vector_base.as_retriever()
 
159
  unsafe_allow_html=True
160
  )
161
 
162
+ # Reset functionality
163
+ if st.button("Reset and Upload a New PDF"):
164
+ st.session_state.clear()
165
+ st.session_state.cleanup_done = False
166
+ st.experimental_rerun()
167
+
168
  if st.session_state.cleanup_done:
169
  cleanup_files()