File size: 1,974 Bytes
ea99abb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import gradio as gr
from tasks.grammar_checking import grammar_checking

GRAMMAR_MODELS = ["gemini-2.0-flash"]
DEFAULT_MODEL = "gemini-2.0-flash"

def grammar_ui():
    with gr.Row():
        with gr.Column(scale=1):
            input_text = gr.Textbox(
                label="Input Text",
                lines=6,
                placeholder="Enter text to check grammar and spelling...",
                elem_id="grammar-input-text"
            )
            gr.Examples(
                examples=[
                    ["This is a smple sentence with errrors."],
                    ["I has went to the store yesterday."]
                ],
                inputs=[input_text],
                label="Examples"
            )
            check_btn = gr.Button("Check Grammar & Spelling", variant="primary")
            model_dropdown = gr.Dropdown(
                GRAMMAR_MODELS,
                value=DEFAULT_MODEL,
                label="Model",
                interactive=True,
                elem_id="grammar-model-dropdown"
            )
            custom_instructions = gr.Textbox(
                label="Custom Instructions (optional)",
                lines=2,
                placeholder="Add any custom instructions for the model...",
                elem_id="grammar-custom-instructions"
            )
        with gr.Column(scale=1):
            output_box = gr.Textbox(
                label="Corrected Text",
                lines=3,
                interactive=False,
                elem_id="grammar-output"
            )
        def run_grammar_checking(text, model, custom_instructions):
            return grammar_checking(
                text=text,
                model=model,
                custom_instructions=custom_instructions,
                use_llm=True
            )
        check_btn.click(
            run_grammar_checking,
            inputs=[input_text, model_dropdown, custom_instructions],
            outputs=output_box
        )