Yoshinoheart commited on
Commit
16a696d
·
1 Parent(s): 350e306
Files changed (1) hide show
  1. app.py +34 -16
app.py CHANGED
@@ -30,31 +30,49 @@ def main():
30
 
31
  # Check button
32
  if st.button("Check"):
33
- # Spelling correction
34
- corrected_spelling = fix_spelling(text_input)[0]['generated_text']
35
 
36
- # Grammar correction
37
- result = happy_tt.generate_text(f"grammar: {text_input}", args=args)
38
- corrected_grammar = result.text
39
 
40
- # Increment counters if corrections were made
41
- if corrected_spelling != text_input:
42
- spelling_counter += 1
43
- if corrected_grammar != text_input:
44
- grammar_counter += 1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
 
46
  # Display corrected text
47
  st.subheader("Corrected Text:")
48
- st.write(corrected_grammar) # Display grammar-corrected text
49
 
50
  # Display spelling correction if there's a difference
51
- if corrected_spelling != corrected_grammar:
52
- st.write(f"Spelling was also corrected to: {corrected_spelling}")
 
53
 
54
  # Display counters
55
- st.sidebar.subheader("Corrections Summary")
56
- st.sidebar.write(f"Spelling Corrections: {spelling_counter}")
57
- st.sidebar.write(f"Grammar Corrections: {grammar_counter}")
58
 
59
  if __name__ == "__main__":
60
  main()
 
30
 
31
  # Check button
32
  if st.button("Check"):
33
+ # Split the text into manageable chunks
34
+ text_chunks = split_text(text_input)
35
 
36
+ corrected_spelling_chunks = []
37
+ corrected_grammar_chunks = []
 
38
 
39
+ # Process each chunk
40
+ for chunk in text_chunks:
41
+ try:
42
+ # Spelling correction
43
+ corrected_spelling = fix_spelling(chunk)[0]['generated_text']
44
+ corrected_spelling_chunks.append(corrected_spelling)
45
+
46
+ # Grammar correction
47
+ result = happy_tt.generate_text(f"grammar: {chunk}", args=args)
48
+ corrected_grammar = result.text
49
+ corrected_grammar_chunks.append(corrected_grammar)
50
+
51
+ # Increment counters if corrections were made
52
+ if corrected_spelling != chunk:
53
+ spelling_counter += 1
54
+ if corrected_grammar != chunk:
55
+ grammar_counter += 1
56
+ except Exception as e:
57
+ st.error(f"Error processing chunk: {chunk}\n{e}")
58
+
59
+ # Combine chunks back into full text
60
+ corrected_spelling_text = ' '.join(corrected_spelling_chunks)
61
+ corrected_grammar_text = ' '.join(corrected_grammar_chunks)
62
 
63
  # Display corrected text
64
  st.subheader("Corrected Text:")
65
+ st.write(corrected_grammar_text) # Display grammar-corrected text
66
 
67
  # Display spelling correction if there's a difference
68
+ if corrected_spelling_text != corrected_grammar_text:
69
+ st.write("Spelling was also corrected to:")
70
+ st.write(corrected_spelling_text)
71
 
72
  # Display counters
73
+ st.subheader("Corrections Summary")
74
+ st.write(f"Spelling Corrections: {spelling_counter}")
75
+ st.write(f"Grammar Corrections: {grammar_counter}")
76
 
77
  if __name__ == "__main__":
78
  main()