|
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 |
|
) |
|
|