Michelvh commited on
Commit
e5cdcd9
·
1 Parent(s): 9182f58

update frame creation

Browse files
Files changed (1) hide show
  1. app.py +26 -2
app.py CHANGED
@@ -42,8 +42,8 @@ def flatten(l):
42
  return [item for sublist in l for item in sublist]
43
 
44
 
45
- def run_model_with_frames(text):
46
- frames = chunkText(text)
47
  result = set()
48
  for frame in frames:
49
  questions = flatten(hf_run_model(frame))
@@ -56,5 +56,29 @@ def run_model_with_frames(text):
56
  return output_string
57
 
58
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  iface = gr.Interface(fn=run_model_with_frames, inputs="text", outputs="text")
60
  iface.launch()
 
42
  return [item for sublist in l for item in sublist]
43
 
44
 
45
+ def run_model_with_frames(text, framesize=4, overlap=3):
46
+ frames = create_frames(text, framesize, overlap)
47
  result = set()
48
  for frame in frames:
49
  questions = flatten(hf_run_model(frame))
 
56
  return output_string
57
 
58
 
59
+ def create_frames(text, framesize=4, overlap=3):
60
+ sentences = tokenize.sent_tokenize(text)
61
+ frames = []
62
+ stepsize = framesize - overlap
63
+ index = 0
64
+ sentenceslength = len(sentences)
65
+ while index < sentenceslength:
66
+ endindex = index + framesize
67
+ if (endindex > sentenceslength):
68
+ frame = " ".join(sentences[-framesize:])
69
+ index = sentenceslength
70
+ else:
71
+ frame = " ".join(sentences[index:endindex])
72
+ index += stepsize
73
+ frames.append(frame)
74
+ return frames
75
+
76
+
77
+ def ensure_questionmark(question):
78
+ if question.endswith("?"):
79
+ return question
80
+ return question + "?"
81
+
82
+
83
  iface = gr.Interface(fn=run_model_with_frames, inputs="text", outputs="text")
84
  iface.launch()