Spaces:
Sleeping
Sleeping
File size: 1,538 Bytes
7dfd165 1fa2e81 7dfd165 354f3db 7dfd165 354f3db 7dfd165 354f3db 7dfd165 354f3db 7dfd165 354f3db 7dfd165 354f3db |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
import gradio as gr
from transformers import pipeline
# Load the sentiment analysis pipeline
sentiment_pipeline = pipeline("sentiment-analysis")
# Function to process input text
def analyze_sentiment(text):
if not text.strip():
return "β οΈ Please enter some text."
result = sentiment_pipeline(text)[0]
label_emoji = "π" if result["label"] == "POSITIVE" else "π"
return f"{label_emoji} **{result['label']}** (confidence: `{round(result['score'], 3)}`)"
# Create a more styled interface using Gradio Blocks
with gr.Blocks(title="Sentiment Analyzer") as demo:
gr.Markdown(
"""
# π§ Sentiment Analysis App
_Enter a sentence to discover its emotional tone!_
Uses `distilbert-base-uncased-finetuned-sst-2-english` from Hugging Face π€
---
"""
)
with gr.Row():
with gr.Column():
input_text = gr.Textbox(
placeholder="Type something like 'I love this app!'",
label="Your Text",
lines=3
)
submit_btn = gr.Button("π Analyze")
with gr.Column():
output = gr.Markdown(label="Sentiment Result")
submit_btn.click(fn=analyze_sentiment, inputs=input_text, outputs=output)
gr.Markdown("---")
gr.Markdown("Made with β€οΈ using [Gradio](https://gradio.app) and [Hugging Face Transformers](https://huggingface.co./transformers/)")
# For local testing; not required for Spaces
if __name__ == "__main__":
demo.launch()
|