realfreko commited on
Commit
db51262
1 Parent(s): 153ee86

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -15
app.py CHANGED
@@ -36,21 +36,16 @@ clear = st.button("Clear text input", on_click=clear_text)
36
 
37
  if submit:
38
  if text is not None:
39
- df = []
40
- df = pd.DataFrame(df, columns=['abstract'])
41
- df.loc[0] = [text]
42
  nlp = English()
43
  sentencizer = nlp.add_pipe("sentencizer")
44
- doc = nlp(df['abstract'][0])
45
  abstract_lines = [str(sent) for sent in list(doc.sents)]
46
- total_lines_in_sample = len(abstract_lines)
47
- sample_lines = []
48
- for i, line in enumerate(abstract_lines):
49
- sample_dict = {}
50
- sample_dict["text"] = str(line)
51
- sample_dict["line_number"] = i
52
- sample_dict["total_lines"] = total_lines_in_sample - 1
53
- sample_lines.append(sample_dict)
54
 
55
  test = pd.DataFrame(sample_lines)
56
  testing_sentences = test['text'].tolist()
@@ -60,9 +55,8 @@ if submit:
60
  new_model_probs = new_model.predict(testing_dataset)
61
  new_model_preds = tf.argmax(new_model_probs, axis=1)
62
  test_pred_classes = [label_encoder.classes_[pred] for pred in new_model_preds]
63
- test["prediction"] = test_pred_classes # create column with test prediction class names
64
  test["pred_prob"] = tf.reduce_max(new_model_probs, axis=1).numpy()
65
- dict_abstract = enumerate(abstract_lines)
66
 
67
- for i, line in dict_abstract:
68
  st.write(f'{test_pred_classes[i]} : {line}')
 
36
 
37
  if submit:
38
  if text is not None:
 
 
 
39
  nlp = English()
40
  sentencizer = nlp.add_pipe("sentencizer")
41
+ doc = nlp(text)
42
  abstract_lines = [str(sent) for sent in list(doc.sents)]
43
+
44
+ sample_lines = [{
45
+ "text": str(line),
46
+ "line_number": i,
47
+ "total_lines": len(abstract_lines) - 1
48
+ } for i, line in enumerate(abstract_lines)]
 
 
49
 
50
  test = pd.DataFrame(sample_lines)
51
  testing_sentences = test['text'].tolist()
 
55
  new_model_probs = new_model.predict(testing_dataset)
56
  new_model_preds = tf.argmax(new_model_probs, axis=1)
57
  test_pred_classes = [label_encoder.classes_[pred] for pred in new_model_preds]
58
+ test["prediction"] = test_pred_classes
59
  test["pred_prob"] = tf.reduce_max(new_model_probs, axis=1).numpy()
 
60
 
61
+ for i, line in enumerate(abstract_lines):
62
  st.write(f'{test_pred_classes[i]} : {line}')