Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
from transformers import pipeline
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
-
# Load
|
| 5 |
sentiment = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english")
|
| 6 |
|
| 7 |
def get_sentiment(text):
|
|
@@ -10,11 +10,16 @@ def get_sentiment(text):
|
|
| 10 |
score = round(output[0]['score'], 2)
|
| 11 |
return label, score
|
| 12 |
|
|
|
|
|
|
|
|
|
|
| 13 |
interface = gr.Interface(
|
| 14 |
fn=get_sentiment,
|
| 15 |
inputs=gr.Textbox(lines=2, placeholder="Enter text here..."),
|
| 16 |
outputs=["text", "number"],
|
| 17 |
-
title=
|
| 18 |
)
|
| 19 |
|
| 20 |
-
|
|
|
|
|
|
|
|
|
| 1 |
from transformers import pipeline
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
+
# Load lightweight sentiment model (important for Spaces!)
|
| 5 |
sentiment = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english")
|
| 6 |
|
| 7 |
def get_sentiment(text):
|
|
|
|
| 10 |
score = round(output[0]['score'], 2)
|
| 11 |
return label, score
|
| 12 |
|
| 13 |
+
title = "Sentiment analysis prototype"
|
| 14 |
+
|
| 15 |
+
# Gradio interface without .launch() (Spaces handles it)
|
| 16 |
interface = gr.Interface(
|
| 17 |
fn=get_sentiment,
|
| 18 |
inputs=gr.Textbox(lines=2, placeholder="Enter text here..."),
|
| 19 |
outputs=["text", "number"],
|
| 20 |
+
title=title
|
| 21 |
)
|
| 22 |
|
| 23 |
+
# Optional: include launch only for local testing
|
| 24 |
+
if __name__ == "__main__":
|
| 25 |
+
interface.launch()
|