import gradio as gr from gradio.themes import Soft from gradio.themes.utils import colors, fonts, sizes from chains.pipelines import main_chain from utils.formatter import format_output from ui.theme import orange_theme colors.orange_red = colors.Color( name="orange_red", c50="#FFF0E5", c100="#FFE0CC", c200="#FFC299", c300="#FFA366", c400="#FF8533", c500="#FF4500", c600="#E63E00", c700="#CC3700", c800="#B33000", c900="#992900", c950="#802200", ) class OrangeRedTheme(Soft): def __init__(self): super().__init__( primary_hue=colors.orange_red, secondary_hue=colors.orange_red, neutral_hue=colors.slate, text_size=sizes.text_lg, font=(fonts.GoogleFont("Outfit"), "Arial", "sans-serif"), font_mono=(fonts.GoogleFont("IBM Plex Mono"), "monospace"), ) super().set( body_background_fill="linear-gradient(135deg, *primary_200, *primary_100)", button_primary_background_fill="linear-gradient(90deg, *secondary_500, *secondary_600)", button_primary_background_fill_hover="linear-gradient(90deg, *secondary_600, *secondary_700)", button_primary_text_color="white", block_border_width="3px", block_shadow="*shadow_drop_lg", ) orange_red_theme = OrangeRedTheme() css_style = """ #container { max-width: 1280px; /* wider layout */ margin: auto; } @media (min-width: 1600px) { #container { max-width: 1440px; } } #title h1 { font-size: 2.4em !important; } """ def run_chain(text: str, tone: str): if not text.strip(): return "Please enter text." result = main_chain.invoke({"text": text, "tone": tone}) return format_output(result, text) with gr.Blocks(title="English Writing Coach") as demo: with gr.Column(elem_id="container"): gr.Markdown("# 🧠 English Writing & Grammar Coach") gr.Markdown(""" Improve your English: correct grammar, rewrite fluently, adjust tone, detect AI text, get suggestions. """) with gr.Row(equal_height=True): with gr.Column(): input_text = gr.Textbox( label="Your English Text", lines=15, placeholder="Type your English text here..." ) tone = gr.Dropdown( ["Neutral", "Formal", "Informal", "Professional", "Academic", "Friendly"], value="Neutral", label="Tone" ) btn = gr.Button("Analyze & Improve", variant="primary") with gr.Column(): output = gr.Textbox( label="Analysis & Improved Versions", lines=24 ) gr.Examples( examples=[ "I wants learn english fast but its difficult for me.", "Company will launching new phone which is very cool.", ], inputs=input_text ) gr.Markdown( "*Powered by Hugging Face Inference API · Free tier rate limits apply*" ) btn.click(run_chain, [input_text, tone], output) if __name__ == "__main__": demo.queue().launch( theme=orange_red_theme, css=css_style, show_error=True, server_name="0.0.0.0", server_port=7860, debug=True )