Spaces:
Sleeping
Sleeping
Add all files
Browse files- README.md +10 -2
- app.py +23 -0
- requirements.txt +3 -0
README.md
CHANGED
|
@@ -1,13 +1,21 @@
|
|
| 1 |
---
|
| 2 |
title: Sentiment Analysis
|
| 3 |
-
emoji:
|
| 4 |
colorFrom: blue
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 5.11.0
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: mit
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
---
|
| 12 |
|
| 13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
title: Sentiment Analysis
|
| 3 |
+
emoji: π
|
| 4 |
colorFrom: blue
|
| 5 |
+
colorTo: green
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 5.11.0
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: mit
|
| 11 |
+
tags:
|
| 12 |
+
- sentiment-analysis
|
| 13 |
+
- NLP
|
| 14 |
+
- machine-learning
|
| 15 |
+
- gradio
|
| 16 |
+
- transformers
|
| 17 |
+
models:
|
| 18 |
+
- distilbert-base-uncased-finetuned-sst-2-english
|
| 19 |
---
|
| 20 |
|
| 21 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load model
|
| 5 |
+
sentiment_model = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english")
|
| 6 |
+
|
| 7 |
+
# Define function for inference
|
| 8 |
+
def analyze_sentiment(text):
|
| 9 |
+
results = sentiment_model(text)
|
| 10 |
+
return f"Sentiment: {results[0]['label']} (Confidence: {results[0]['score']:.2f})"
|
| 11 |
+
|
| 12 |
+
# Create Gradio interface
|
| 13 |
+
interface = gr.Interface(
|
| 14 |
+
fn=analyze_sentiment,
|
| 15 |
+
inputs=gr.Textbox(lines=2, placeholder="Enter text here..."),
|
| 16 |
+
outputs="text",
|
| 17 |
+
title="Sentiment Analysis App",
|
| 18 |
+
description="Enter a sentence to analyze its sentiment using a fine-tuned DistilBERT model.",
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
# Launch the app
|
| 22 |
+
if __name__ == "__main__":
|
| 23 |
+
interface.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch
|
| 2 |
+
gradio
|
| 3 |
+
transformers
|