Muhammad Anas Akhtar
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,12 +3,12 @@ import gradio as gr
|
|
| 3 |
from transformers import pipeline
|
| 4 |
|
| 5 |
# Initialize the sentiment-analysis pipeline
|
| 6 |
-
|
| 7 |
|
| 8 |
-
# Define a function to analyze text
|
| 9 |
-
def
|
| 10 |
# Get the result from the pipeline
|
| 11 |
-
result =
|
| 12 |
# Extract label (e.g., Positive/Negative) and confidence score
|
| 13 |
label = result[0]['label']
|
| 14 |
confidence = round(result[0]['score'] * 100, 2)
|
|
@@ -18,11 +18,11 @@ def analyze_semantics(input_text):
|
|
| 18 |
gr.close_all()
|
| 19 |
|
| 20 |
Demo = gr.Interface(
|
| 21 |
-
fn=
|
| 22 |
-
inputs=[gr.Textbox(label="Enter Text for
|
| 23 |
-
outputs=[gr.Textbox(label="
|
| 24 |
-
title="
|
| 25 |
-
description="This application performs
|
| 26 |
)
|
| 27 |
|
| 28 |
# Launch the app with a public link
|
|
|
|
| 3 |
from transformers import pipeline
|
| 4 |
|
| 5 |
# Initialize the sentiment-analysis pipeline
|
| 6 |
+
sentiment_analysis = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english")
|
| 7 |
|
| 8 |
+
# Define a function to analyze text sentiment
|
| 9 |
+
def analyze_sentiment(input_text):
|
| 10 |
# Get the result from the pipeline
|
| 11 |
+
result = sentiment_analysis(input_text)
|
| 12 |
# Extract label (e.g., Positive/Negative) and confidence score
|
| 13 |
label = result[0]['label']
|
| 14 |
confidence = round(result[0]['score'] * 100, 2)
|
|
|
|
| 18 |
gr.close_all()
|
| 19 |
|
| 20 |
Demo = gr.Interface(
|
| 21 |
+
fn=analyze_sentiment,
|
| 22 |
+
inputs=[gr.Textbox(label="Enter Text for Sentiment Analysis", lines=5)],
|
| 23 |
+
outputs=[gr.Textbox(label="Sentiment Analysis Result", lines=2)],
|
| 24 |
+
title="Sentiment Analysis App",
|
| 25 |
+
description="This application performs sentiment analysis to determine whether the text is positive or negative."
|
| 26 |
)
|
| 27 |
|
| 28 |
# Launch the app with a public link
|