import gradio as gr from transformers import pipeline # Load grammar correction & dictionary models corrector = pipeline("text2text-generation", model="vennify/t5-base-grammar-correction") dictionary = pipeline("text2text-generation", model="google/flan-t5-small") def smart_gpt(input_text): input_text = input_text.strip() # Single word check if " " not in input_text: meaning = dictionary(f"define {input_text}")[0]['generated_text'] return f""" 🧠 **SmartGPT Word Check** ✅ **Word:** {input_text} 📖 **Meaning:** {meaning} 💬 **Gen Z Vibe:** Bro that word lowkey slaps 😎 """ # Sentence check correction = corrector(input_text)[0]['generated_text'].strip() if correction.lower() == input_text.lower(): return f""" 🧠 **SmartGPT Sentence Check** ✅ **Sentence:** Looks perfect, chief 🔥 ✨ **Better Version:** {correction} 💭 **Gen Z Vibe:** You cooked, no cap 😎 """ else: return f""" 🧠 **SmartGPT Grammar Fix** ❌ **Found issues in:** {input_text} ✅ **Fixed Version:** {correction} ✨ **Better Version:** {correction} 💭 **Gen Z Vibe:** Bro we fixed it fr 😭🔥 """ # Interface UI setup demo = gr.Interface( fn=smart_gpt, inputs=gr.Textbox(lines=2, placeholder="Type a word or sentence here...", label="Enter text 💬"), outputs=gr.Markdown(label="SmartGPT Response 💡"), title="SmartGPT 🔥", description="Your AI homie for spelling, grammar & Gen Z style chats 😎", theme="soft", # clean pastel theme ) demo.launch()