Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load a pre-trained sentiment-analysis model
|
| 5 |
+
sentiment_analyzer = pipeline("sentiment-analysis")
|
| 6 |
+
|
| 7 |
+
def analyze_text(text):
|
| 8 |
+
result = sentiment_analyzer(text)[0]
|
| 9 |
+
label = result["label"]
|
| 10 |
+
score = round(result["score"], 3)
|
| 11 |
+
return f"{label} ({score})"
|
| 12 |
+
|
| 13 |
+
demo = gr.Interface(
|
| 14 |
+
fn=analyze_text,
|
| 15 |
+
inputs=gr.Textbox(label="Enter text to analyze"),
|
| 16 |
+
outputs=gr.Textbox(label="Sentiment Prediction"),
|
| 17 |
+
title="CIS1160 Sentiment Inference Demo",
|
| 18 |
+
description="This model runs inference on text to predict sentiment (positive/negative)."
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
demo.launch()
|