|
|
import gradio as gr |
|
|
from transformers import pipeline |
|
|
|
|
|
|
|
|
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() |
|
|
|
|
|
|
|
|
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 π |
|
|
""" |
|
|
|
|
|
|
|
|
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 ππ₯ |
|
|
""" |
|
|
|
|
|
|
|
|
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", |
|
|
) |
|
|
|
|
|
demo.launch() |
|
|
|