Update app.py
Browse files
app.py
CHANGED
|
@@ -1,20 +1,26 @@
|
|
| 1 |
-
|
| 2 |
from transformers import pipeline
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
def predictive_model(texts):
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
interface
|
| 15 |
-
inputs="text",
|
| 16 |
-
outputs=["text","number"],
|
| 17 |
-
title="Sentiment-Analysis-App",
|
| 18 |
-
description="Gave your text my machine is going to detect Positive / Negative "
|
| 19 |
-
)
|
| 20 |
-
interface.launch()
|
|
|
|
|
|
|
| 1 |
from transformers import pipeline
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
+
# Label mapping
|
| 5 |
+
human_read = {"LABEL_0": "Negative", "LABEL_1": "Positive"}
|
| 6 |
+
|
| 7 |
+
# Load model
|
| 8 |
+
sentimental = pipeline("text-classification", model="Dmyadav2001/Sentimental-Analysis")
|
| 9 |
+
|
| 10 |
+
# Prediction function
|
| 11 |
def predictive_model(texts):
|
| 12 |
+
result = sentimental(texts)
|
| 13 |
+
sentiment = human_read[result[0]["label"]]
|
| 14 |
+
score = result[0]["score"]
|
| 15 |
+
return sentiment, score
|
| 16 |
+
|
| 17 |
+
# Gradio Interface
|
| 18 |
+
interface = gr.Interface(
|
| 19 |
+
fn=predictive_model,
|
| 20 |
+
inputs="text",
|
| 21 |
+
outputs=["text", "number"],
|
| 22 |
+
title="Sentiment-Analysis-App",
|
| 23 |
+
description="Give your text, and my model will predict whether it's Positive or Negative."
|
| 24 |
+
)
|
| 25 |
|
| 26 |
+
interface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|