Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,8 +4,8 @@ import os
|
|
4 |
|
5 |
checker = SpellChecker()
|
6 |
|
7 |
-
# Your CSS styles (copied from index.html)
|
8 |
css = """
|
|
|
9 |
* { margin: 0; padding: 0; box-sizing: border-box; }
|
10 |
body {
|
11 |
font-family: 'Poppins', sans-serif;
|
@@ -14,52 +14,22 @@ body {
|
|
14 |
min-height: 100vh;
|
15 |
padding: 40px;
|
16 |
}
|
17 |
-
|
18 |
-
text-align: center;
|
19 |
-
font-weight: 700;
|
20 |
-
margin-bottom: 40px;
|
21 |
-
font-size: 2.5rem;
|
22 |
-
}
|
23 |
-
.output {
|
24 |
-
background-color: rgba(255, 255, 255, 0.15);
|
25 |
-
backdrop-filter: blur(12px);
|
26 |
-
padding: 25px;
|
27 |
-
border-radius: 20px;
|
28 |
-
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
|
29 |
-
margin-top: 20px;
|
30 |
-
}
|
31 |
-
.issues li { color: #ff9f9f; }
|
32 |
-
textarea {
|
33 |
-
width: 100%;
|
34 |
-
height: 150px;
|
35 |
-
padding: 15px;
|
36 |
-
border-radius: 10px;
|
37 |
-
border: none;
|
38 |
-
font-size: 16px;
|
39 |
-
resize: none;
|
40 |
-
}
|
41 |
"""
|
42 |
|
43 |
def check_text(text):
|
44 |
corrected_spelling = checker.correct_spelling(text)
|
45 |
corrected_grammar, grammar_issues = checker.correct_grammar(text)
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
return (
|
50 |
-
corrected_spelling,
|
51 |
-
corrected_grammar,
|
52 |
-
f"<ul class='issues'>{issues_html}</ul>"
|
53 |
-
)
|
54 |
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
""")
|
59 |
|
60 |
with gr.Row():
|
61 |
text_input = gr.Textbox(
|
62 |
-
label="
|
63 |
placeholder="Type or paste your text here...",
|
64 |
lines=10
|
65 |
)
|
@@ -67,17 +37,20 @@ with gr.Blocks(css=css, title="Spell & Grammar Checker") as demo:
|
|
67 |
submit_btn = gr.Button("β¨ Check Now", variant="primary")
|
68 |
|
69 |
with gr.Column():
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
submit_btn.click(
|
75 |
-
check_text,
|
76 |
inputs=text_input,
|
77 |
-
outputs=[
|
78 |
)
|
79 |
|
80 |
-
|
81 |
-
|
82 |
-
server_name="0.0.0.0"
|
|
|
|
|
|
|
83 |
)
|
|
|
4 |
|
5 |
checker = SpellChecker()
|
6 |
|
|
|
7 |
css = """
|
8 |
+
/* Your existing CSS styles */
|
9 |
* { margin: 0; padding: 0; box-sizing: border-box; }
|
10 |
body {
|
11 |
font-family: 'Poppins', sans-serif;
|
|
|
14 |
min-height: 100vh;
|
15 |
padding: 40px;
|
16 |
}
|
17 |
+
/* Include all other CSS rules from your index.html */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
"""
|
19 |
|
20 |
def check_text(text):
|
21 |
corrected_spelling = checker.correct_spelling(text)
|
22 |
corrected_grammar, grammar_issues = checker.correct_grammar(text)
|
23 |
+
issues = "\n".join([f"β’ {issue}" for issue in grammar_issues]) if grammar_issues else "No issues found"
|
24 |
+
return corrected_spelling, corrected_grammar, issues
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
+
# Create Gradio interface
|
27 |
+
with gr.Blocks(css=css, title="Spell Checker") as app:
|
28 |
+
gr.Markdown("# Spell & Grammar Checker")
|
|
|
29 |
|
30 |
with gr.Row():
|
31 |
text_input = gr.Textbox(
|
32 |
+
label="Input Text",
|
33 |
placeholder="Type or paste your text here...",
|
34 |
lines=10
|
35 |
)
|
|
|
37 |
submit_btn = gr.Button("β¨ Check Now", variant="primary")
|
38 |
|
39 |
with gr.Column():
|
40 |
+
spelling_output = gr.Textbox(label="β
Corrected Spelling")
|
41 |
+
grammar_output = gr.Textbox(label="π Grammar Suggestions")
|
42 |
+
issues_output = gr.Textbox(label="π¨ Issues Found", lines=4)
|
43 |
+
|
44 |
submit_btn.click(
|
45 |
+
fn=check_text,
|
46 |
inputs=text_input,
|
47 |
+
outputs=[spelling_output, grammar_output, issues_output]
|
48 |
)
|
49 |
|
50 |
+
# Hugging Face specific launch configuration
|
51 |
+
app.launch(
|
52 |
+
server_name="0.0.0.0",
|
53 |
+
server_port=int(os.getenv("PORT", "7860")),
|
54 |
+
share=False,
|
55 |
+
enable_queue=True
|
56 |
)
|