File size: 1,424 Bytes
00f8d40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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")
def analyze_sentiment(text):
result = sentiment_pipeline(text)[0]
label = result["label"]
score = result["score"]
return f"Sentiment: {label}\nConfidence: {score:.2f}"
# Create the Gradio interface
iface = gr.Interface(
fn=analyze_sentiment,
inputs=gr.Textbox(placeholder="Enter text to analyze..."),
outputs=gr.Textbox(),
title="Sentiment Analysis App",
description="Enter a sentence to determine its sentiment (positive or negative).",
examples=[
["I love this product! It's amazing!"],
["I am very disappointed with the service."]
]
)
import gradio as gr
from transformers import pipeline
# Load the sentiment analysis pipeline
sentiment_pipeline = pipeline("sentiment-analysis")
def analyze_sentiment(text):
result = sentiment_pipeline(text)[0]
label = result["label"]
score = result["score"]
return f"Sentiment: {label}\nConfidence: {score:.2f}"
# Create the Gradio interface
iface = gr.Interface(
fn=analyze_sentiment,
inputs=gr.Textbox(placeholder="Enter text to analyze..."),
outputs=gr.Textbox(),
title="Sentiment Analysis App",
description="Enter a sentence to determine its sentiment (positive or negative).",
examples=[
["I love this product! It's amazing!"],
["I am very disappointed with the service."]
]
)
# Launch the app
if __name__ == "__main__":
iface.launch()