Update app.py
Browse files
app.py
CHANGED
|
@@ -1,27 +1,28 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
from transformers import pipeline
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
| 13 |
inputs=gr.Textbox(placeholder="Enter text to analyze..."),
|
| 14 |
-
outputs=gr.Textbox(),
|
| 15 |
-
title="Sentiment Analysis App",
|
| 16 |
description="Enter a sentence to determine its sentiment (positive or negative).",
|
| 17 |
-
examples=[
|
| 18 |
["I love this product! It's amazing!"],
|
| 19 |
["I am very disappointed with the service."]
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
# Launch the app if __name__ == "__main__": iface.launch()
|
| 23 |
-
if __name__ == "__main__":
|
| 24 |
-
iface.launch()
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load the sentiment analysis pipeline
|
| 5 |
+
sentiment_pipeline = pipeline("sentiment-analysis")
|
| 6 |
+
|
| 7 |
+
def analyze_sentiment(text):
|
| 8 |
+
result = sentiment_pipeline(text)[0]
|
| 9 |
+
label = result["label"]
|
| 10 |
+
score = result["score"]
|
| 11 |
+
return f"Sentiment: {label}\nConfidence: {score:.2f}"
|
| 12 |
+
|
| 13 |
+
# Create the Gradio interface
|
| 14 |
+
iface = gr.Interface(
|
| 15 |
+
fn=analyze_sentiment,
|
| 16 |
inputs=gr.Textbox(placeholder="Enter text to analyze..."),
|
| 17 |
+
outputs=gr.Textbox(),
|
| 18 |
+
title="Sentiment Analysis App",
|
| 19 |
description="Enter a sentence to determine its sentiment (positive or negative).",
|
| 20 |
+
examples=[
|
| 21 |
["I love this product! It's amazing!"],
|
| 22 |
["I am very disappointed with the service."]
|
| 23 |
+
]
|
| 24 |
+
)
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
+
# Launch the app if __name__ == "__main__":
|
| 27 |
+
if __name__ == "__main__":
|
| 28 |
+
iface.launch()
|