import gradio as gr from transformers import pipeline # Load a tiny, fast model โ€” runs on CPU in seconds sentiment = pipeline( "sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english", ) def analyze(text: str) -> str: if not text.strip(): return "Please enter some text." result = sentiment(text)[0] label = result["label"].capitalize() score = round(result["score"] * 100, 1) emoji = "๐Ÿ˜Š" if label == "Positive" else "๐Ÿ˜ž" return f"{emoji} **{label}** ({score}% confidence)" demo = gr.Interface( fn=analyze, inputs=gr.Textbox( label="Your text", placeholder="Type anythingโ€ฆ e.g. 'I love building AI apps!'", lines=3, ), outputs=gr.Markdown(label="Sentiment"), title="๐Ÿค— Hello World โ€” AI Sentiment Analysis", description=( "Type a sentence and the model will tell you whether it sounds " "**positive** or **negative**. Powered by DistilBERT on ๐Ÿค— Transformers." ), examples=[ ["I love learning about machine learning!"], ["This assignment is really frustrating."], ["The weather is okay today."], ], cache_examples=False, ) if __name__ == "__main__": demo.launch()