Commit
·
16a696d
1
Parent(s):
350e306
UPDATE
Browse files
app.py
CHANGED
@@ -30,31 +30,49 @@ def main():
|
|
30 |
|
31 |
# Check button
|
32 |
if st.button("Check"):
|
33 |
-
#
|
34 |
-
|
35 |
|
36 |
-
|
37 |
-
|
38 |
-
corrected_grammar = result.text
|
39 |
|
40 |
-
#
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
|
46 |
# Display corrected text
|
47 |
st.subheader("Corrected Text:")
|
48 |
-
st.write(
|
49 |
|
50 |
# Display spelling correction if there's a difference
|
51 |
-
if
|
52 |
-
st.write(
|
|
|
53 |
|
54 |
# Display counters
|
55 |
-
st.
|
56 |
-
st.
|
57 |
-
st.
|
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()
|