Spaces:
Build error
Build error
Commit
·
061a026
1
Parent(s):
e73d0e4
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,2 +1,23 @@
|
|
| 1 |
!pip install gradio
|
| 2 |
-
!pip install transformers
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
!pip install gradio
|
| 2 |
+
!pip install transformers
|
| 3 |
+
import gradio as gr
|
| 4 |
+
from transformers import pipeline
|
| 5 |
+
|
| 6 |
+
# Load the sentiment analysis model
|
| 7 |
+
sentiment = pipeline("sentiment-analysis")
|
| 8 |
+
|
| 9 |
+
def get_sentiment(input_text):
|
| 10 |
+
result = sentiment(input_text)
|
| 11 |
+
label = result[0]['label']
|
| 12 |
+
score = result[0]['score']
|
| 13 |
+
return f"Sentiment: {label}, Score: {score:.4f}"
|
| 14 |
+
|
| 15 |
+
iface = gr.Interface(
|
| 16 |
+
fn=get_sentiment,
|
| 17 |
+
inputs="text",
|
| 18 |
+
outputs="text",
|
| 19 |
+
title="Sentiment Analysis with Transformers",
|
| 20 |
+
description="Analyze sentiment (negative/positive) of input text."
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
iface.launch(inline=False)
|