Jayant399 commited on
Commit
657f915
Β·
verified Β·
1 Parent(s): ad81b48

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -49
app.py CHANGED
@@ -4,68 +4,80 @@ import os
4
 
5
  checker = SpellChecker()
6
 
7
- # Load your HTML template
8
- with open("index.html", "r") as f:
9
- html_template = f.read()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
  def check_text(text):
12
  corrected_spelling = checker.correct_spelling(text)
13
  corrected_grammar, grammar_issues = checker.correct_grammar(text)
14
 
15
- output = f"""
16
- <div class="output">
17
- <h3>βœ… Corrected Spelling:</h3>
18
- <p>{corrected_spelling}</p>
19
- </div>
20
- <div class="output">
21
- <h3>πŸ“ Grammar Suggestions:</h3>
22
- <p>{corrected_grammar}</p>
23
- </div>
24
- """
25
 
26
- if grammar_issues:
27
- output += f"""
28
- <div class="output issues">
29
- <h4>🚨 Issues Found:</h4>
30
- <ul>
31
- {"".join(f"<li>{issue}</li>" for issue in grammar_issues)}
32
- </ul>
33
- </div>
34
- """
35
-
36
- return output
37
 
38
- with gr.Blocks() as demo:
39
- gr.HTML(html_template)
 
 
40
 
41
- text_input = gr.Textbox(visible=False, label="text")
42
- output_area = gr.HTML()
 
 
 
 
43
 
44
- demo.load(
45
- None,
46
- None,
47
- None,
48
- _js="""
49
- () => {
50
- document.querySelector('form').onsubmit = async (e) => {
51
- e.preventDefault();
52
- const text = document.querySelector('textarea').value;
53
- gradioApp.querySelector('#component-1 input').value = text;
54
- gradioApp.querySelector('#component-2 button').click();
55
- }
56
- }
57
- """
58
- )
59
 
60
- text_input.change(
61
  check_text,
62
  inputs=text_input,
63
- outputs=output_area
64
  )
65
 
66
- # Modified launch configuration for Hugging Face
67
  demo.launch(
68
- server_port=int(os.environ.get("PORT", 7860)), # Use Hugging Face's port
69
- server_name="0.0.0.0", # Required for Hugging Face
70
- share=False # Disable public sharing
71
  )
 
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;
12
+ background: linear-gradient(to right, #6a11cb, #2575fc);
13
+ color: #fff;
14
+ min-height: 100vh;
15
+ padding: 40px;
16
+ }
17
+ h1 {
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
+ issues_html = "".join(f"<li>{issue}</li>" for issue in grammar_issues) if grammar_issues else "<li>No issues found</li>"
 
 
 
 
 
 
 
 
 
48
 
49
+ return (
50
+ corrected_spelling,
51
+ corrected_grammar,
52
+ f"<ul class='issues'>{issues_html}</ul>"
53
+ )
 
 
 
 
 
 
54
 
55
+ with gr.Blocks(css=css, title="Spell & Grammar Checker") as demo:
56
+ gr.Markdown("""
57
+ <h1>Spell & Grammar Checker</h1>
58
+ """)
59
 
60
+ with gr.Row():
61
+ text_input = gr.Textbox(
62
+ label="Type your text here",
63
+ placeholder="Type or paste your text here...",
64
+ lines=10
65
+ )
66
 
67
+ submit_btn = gr.Button("✨ Check Now", variant="primary")
68
+
69
+ with gr.Column():
70
+ spelling_out = gr.Textbox(label="βœ… Corrected Spelling")
71
+ grammar_out = gr.Textbox(label="πŸ“ Grammar Suggestions")
72
+ issues_out = gr.HTML(label="🚨 Issues Found")
 
 
 
 
 
 
 
 
 
73
 
74
+ submit_btn.click(
75
  check_text,
76
  inputs=text_input,
77
+ outputs=[spelling_out, grammar_out, issues_out]
78
  )
79
 
 
80
  demo.launch(
81
+ server_port=int(os.environ.get("PORT", 7860)),
82
+ server_name="0.0.0.0"
 
83
  )