zmbfeng commited on
Commit
0caae26
1 Parent(s): c0b7df2

overall working

Browse files
Files changed (1) hide show
  1. app.py +11 -8
app.py CHANGED
@@ -233,7 +233,7 @@ def contradiction_detection_for_sentence(cd_query):
233
  processing_progress_bar = st.progress(0)
234
 
235
  sentence_scores, paragraph_scores = find_sentences_scores(
236
- st.session_state.paragraph_sentence_encodings, query_encoding, processing_progress_bar, total_count)
237
 
238
  sorted_paragraph_scores = sorted(paragraph_scores, key=lambda x: x[0], reverse=True)
239
 
@@ -247,12 +247,12 @@ def contradiction_detection_for_sentence(cd_query):
247
 
248
  if prev_contradiction_detected:
249
  contradiction_detection_result = contradiction_detection(cd_query, top_sentence[1])
250
- st.write("master document page number ", paragraph_from_sorted_paragraph_scores['original_text']['page_num'])
251
- st.write("master document sentence: ", top_sentence[1])
252
- st.write("secondary document sentence: ", cd_query)
253
- st.write(contradiction_detection_result)
254
- if contradiction_detection_result == {"Contradiction"}:
255
 
 
 
 
 
 
256
  st.write(contradiction_detection_result)
257
  # st.write(contradiction_detection(st.session_state.premise, top_sentence[1]))
258
 
@@ -262,7 +262,7 @@ def contradiction_detection_for_sentence(cd_query):
262
  break
263
 
264
 
265
- def find_sentences_scores(paragraph_sentence_encodings, query_encoding, processing_progress_bar, total_count):
266
  paragraph_scores = []
267
  sentence_scores = []
268
  for paragraph_sentence_encoding_index, paragraph_sentence_encoding in enumerate(paragraph_sentence_encodings):
@@ -276,7 +276,8 @@ def find_sentences_scores(paragraph_sentence_encodings, query_encoding, processi
276
  combined_score, similarity_score, commonality_score = add_commonality_to_similarity_score(similarity,
277
  sentence_encoding[
278
  0],
279
- query)
 
280
  sentence_similarities.append((combined_score, sentence_encoding[0], commonality_score))
281
  sentence_scores.append((combined_score, sentence_encoding[0]))
282
 
@@ -315,6 +316,7 @@ if 'paragraph_sentence_encodings' in st.session_state:
315
  query = st.text_input("Enter your query")
316
  if query:
317
  if 'prev_query' not in st.session_state or st.session_state.prev_query != query:
 
318
  st.session_state.prev_query = query
319
  st.session_state.premise = query
320
  contradiction_detection_for_sentence(query)
@@ -322,6 +324,7 @@ if 'paragraph_sentence_encodings' in st.session_state:
322
  uploaded_text_file = st.file_uploader("Choose a .txt file", type="txt")
323
  if uploaded_text_file is not None:
324
  if is_new_txt_file_upload(uploaded_text_file):
 
325
  lines = uploaded_text_file.readlines()
326
 
327
  # Initialize an empty list to store line number and text
 
233
  processing_progress_bar = st.progress(0)
234
 
235
  sentence_scores, paragraph_scores = find_sentences_scores(
236
+ st.session_state.paragraph_sentence_encodings, query_encoding, cd_query, processing_progress_bar, total_count)
237
 
238
  sorted_paragraph_scores = sorted(paragraph_scores, key=lambda x: x[0], reverse=True)
239
 
 
247
 
248
  if prev_contradiction_detected:
249
  contradiction_detection_result = contradiction_detection(cd_query, top_sentence[1])
 
 
 
 
 
250
 
251
+ if contradiction_detection_result == {"Contradiction"}:
252
+ st.write("master document page number ",
253
+ paragraph_from_sorted_paragraph_scores['original_text']['page_num'])
254
+ st.write("master document sentence: ", top_sentence[1])
255
+ st.write("secondary document sentence: ", cd_query)
256
  st.write(contradiction_detection_result)
257
  # st.write(contradiction_detection(st.session_state.premise, top_sentence[1]))
258
 
 
262
  break
263
 
264
 
265
+ def find_sentences_scores(paragraph_sentence_encodings, query_encoding, query_plain, processing_progress_bar, total_count):
266
  paragraph_scores = []
267
  sentence_scores = []
268
  for paragraph_sentence_encoding_index, paragraph_sentence_encoding in enumerate(paragraph_sentence_encodings):
 
276
  combined_score, similarity_score, commonality_score = add_commonality_to_similarity_score(similarity,
277
  sentence_encoding[
278
  0],
279
+ query_plain)
280
+ # print(f"{sentence_encoding[0]} {combined_score} {similarity_score} {commonality_score}")
281
  sentence_similarities.append((combined_score, sentence_encoding[0], commonality_score))
282
  sentence_scores.append((combined_score, sentence_encoding[0]))
283
 
 
316
  query = st.text_input("Enter your query")
317
  if query:
318
  if 'prev_query' not in st.session_state or st.session_state.prev_query != query:
319
+ # if True:
320
  st.session_state.prev_query = query
321
  st.session_state.premise = query
322
  contradiction_detection_for_sentence(query)
 
324
  uploaded_text_file = st.file_uploader("Choose a .txt file", type="txt")
325
  if uploaded_text_file is not None:
326
  if is_new_txt_file_upload(uploaded_text_file):
327
+ #if True:
328
  lines = uploaded_text_file.readlines()
329
 
330
  # Initialize an empty list to store line number and text