SmartGPT / app.py
muiz69's picture
Update app.py
35c15df verified
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()