File size: 856 Bytes
b71fc64 e3537c3 b71fc64 e3537c3 73a919a b71fc64 3688b0a b71fc64 3688b0a b71fc64 624c2c7 3688b0a |
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 |
import gradio as gr
from transformers import pipeline
model = pipeline("sentiment-analysis", model="nlptown/bert-base-multilingual-uncased-sentiment")
def sentiment(text):
analysis = model(text)
return analysis[0]['label']
with gr.Blocks() as app:
gr.Markdown("# Sentiment Analysis")
text_input = gr.Textbox(label="Enter a sentence or paragraph:", lines=10)
analyze_button = gr.Button("Analyze Sentiment")
output_text = gr.Textbox(label="Predicted Sentiment (1 to 5 stars):", interactive=False)
analyze_button.click(sentiment, inputs=text_input, outputs=output_text)
examples = [
"I love this product! It's amazing!",
"This was the worst experience I've ever had."
]
gr.Examples(
examples=examples,
inputs=text_input,
label="Try these examples"
)
app.launch()
|