CCockrum commited on
Commit
06a8979
·
verified ·
1 Parent(s): a5df7cd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -2
app.py CHANGED
@@ -129,6 +129,11 @@ if view == "Artwork Explorer":
129
  st.markdown(f"> {generate_description(query_art)}")
130
 
131
  with st.expander("💬 Ask a question about this artwork"):
 
 
 
 
 
132
  user_question = st.text_input("Your question")
133
  if user_question:
134
  qa_prompt = (
@@ -150,11 +155,18 @@ if view == "Artwork Explorer":
150
  qa_prompt += f"
151
  Question: {user_question}
152
  Answer:"
 
153
  try:
154
  answer = describer(qa_prompt, max_length=100, truncation=True, do_sample=True)[0]["generated_text"]
155
- st.markdown(f"**Answer:** {answer.strip()}")
156
  except Exception as e:
157
- st.error(f"[Answer unavailable: {e}]")
 
 
 
 
 
 
158
 
159
  sim_scores = cosine_similarity([features[query_idx]], features)[0]
160
  ranked = np.argsort(sim_scores)[::-1][1:6]
 
129
  st.markdown(f"> {generate_description(query_art)}")
130
 
131
  with st.expander("💬 Ask a question about this artwork"):
132
+ if st.button("🧹 Clear Conversation"):
133
+ st.session_state.chat_history = []
134
+ if "chat_history" not in st.session_state:
135
+ st.session_state.chat_history = []
136
+
137
  user_question = st.text_input("Your question")
138
  if user_question:
139
  qa_prompt = (
 
155
  qa_prompt += f"
156
  Question: {user_question}
157
  Answer:"
158
+
159
  try:
160
  answer = describer(qa_prompt, max_length=100, truncation=True, do_sample=True)[0]["generated_text"]
161
+ st.session_state.chat_history.append((user_question, answer.strip()))
162
  except Exception as e:
163
+ answer = f"[Answer unavailable: {e}]"
164
+ st.session_state.chat_history.append((user_question, answer))
165
+
166
+ if st.session_state.chat_history:
167
+ for question, response in reversed(st.session_state.chat_history[-5:]):
168
+ st.markdown(f"**You:** {question}")
169
+ st.markdown(f"> {response}")
170
 
171
  sim_scores = cosine_similarity([features[query_idx]], features)[0]
172
  ranked = np.argsort(sim_scores)[::-1][1:6]