Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
# Use a pipeline as a high-level helper
|
| 4 |
+
from transformers import pipeline
|
| 5 |
+
import torch
|
| 6 |
+
import gradio as gr
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
sentiment_Analyzer = pipeline("text-classification", model="distilbert/distilbert-base-uncased-finetuned-sst-2-english")
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def analyzer(text):
|
| 14 |
+
output = (sentiment_Analyzer(text))[0]
|
| 15 |
+
label = output['label']
|
| 16 |
+
score = output['score']
|
| 17 |
+
return label,score
|
| 18 |
+
|
| 19 |
+
# Create the Gradio interface
|
| 20 |
+
interface = gr.Interface(
|
| 21 |
+
fn=analyzer,
|
| 22 |
+
inputs=gr.Textbox(lines=2, placeholder="Enter text here..."),
|
| 23 |
+
outputs=[
|
| 24 |
+
gr.Textbox(label="Sentiment Label", placeholder="Label will appear here..."),
|
| 25 |
+
gr.Number(label="Confidence Score")
|
| 26 |
+
],
|
| 27 |
+
title="Sentiment Analyzer",
|
| 28 |
+
description="Enter text to analyze its sentiment (positive/negative) and get the confidence score."
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
# Launch the Gradio interface
|
| 32 |
+
interface.launch()
|