Jayant399 commited on
Commit
712e0e5
·
verified ·
1 Parent(s): 192eb32

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -14
app.py CHANGED
@@ -3,23 +3,69 @@ from model import SpellChecker
3
 
4
  checker = SpellChecker()
5
 
 
 
 
 
6
  def check_text(text):
7
  corrected_spelling = checker.correct_spelling(text)
8
- corrected_grammar, _ = checker.correct_grammar(text)
9
-
10
- return f"""
11
- ## ✅ Corrected Text:
12
- {corrected_grammar}
13
 
14
- Note: For full grammar checking, run locally with Java installed.
 
 
 
 
 
 
 
 
 
15
  """
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
- iface = gr.Interface(
18
- fn=check_text,
19
- inputs=gr.Textbox(label="Enter text", lines=10),
20
- outputs=gr.Markdown(),
21
- title="Spell Checker",
22
- examples=[["Helo world!"]]
23
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
- iface.launch()
 
3
 
4
  checker = SpellChecker()
5
 
6
+ # Load your HTML template
7
+ with open("index.html", "r") as f:
8
+ html_template = f.read()
9
+
10
  def check_text(text):
11
  corrected_spelling = checker.correct_spelling(text)
12
+ corrected_grammar, grammar_issues = checker.correct_grammar(text)
 
 
 
 
13
 
14
+ # Format the output to match your HTML structure
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
+ # Create custom Gradio interface
39
+ with gr.Blocks() as demo:
40
+ # Inject your entire HTML
41
+ gr.HTML(html_template)
42
+
43
+ # Add interactive components
44
+ text_input = gr.Textbox(visible=False, label="text")
45
+ output_area = gr.HTML()
46
+
47
+ # JavaScript to handle form submission
48
+ demo.load(
49
+ None,
50
+ None,
51
+ None,
52
+ _js="""
53
+ () => {
54
+ document.querySelector('form').onsubmit = async (e) => {
55
+ e.preventDefault();
56
+ const text = document.querySelector('textarea').value;
57
+ const result = await gradioApp.querySelector('#component-1 input').value = text;
58
+ gradioApp.querySelector('#component-2 button').click();
59
+ }
60
+ }
61
+ """
62
+ )
63
+
64
+ # Connect function to components
65
+ text_input.change(
66
+ check_text,
67
+ inputs=text_input,
68
+ outputs=output_area
69
+ )
70
 
71
+ demo.launch()