Spaces:
Sleeping
Sleeping
mansi sharma commited on
Commit ·
a788079
1
Parent(s): 0112ec7
Added app and requirements
Browse files- app.py +30 -0
- requirements.txt +3 -0
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load model from Hugging Face
|
| 5 |
+
model_name = "sohan-ai/sentiment-analysis-model-amazon-reviews"
|
| 6 |
+
classifier = pipeline("sentiment-analysis", model=model_name)
|
| 7 |
+
|
| 8 |
+
# Prediction function
|
| 9 |
+
def predict_sentiment(text):
|
| 10 |
+
if text.strip() == "":
|
| 11 |
+
return "Please enter some text."
|
| 12 |
+
|
| 13 |
+
result = classifier(text)[0]
|
| 14 |
+
label = result["label"]
|
| 15 |
+
score = result["score"]
|
| 16 |
+
|
| 17 |
+
return f"Sentiment: {label} (Confidence: {score:.2f})"
|
| 18 |
+
|
| 19 |
+
# Gradio UI
|
| 20 |
+
iface = gr.Interface(
|
| 21 |
+
fn=predict_sentiment,
|
| 22 |
+
inputs=gr.Textbox(lines=5, placeholder="Enter your review here..."),
|
| 23 |
+
outputs="text",
|
| 24 |
+
title="Sentiment Analysis App",
|
| 25 |
+
description="Enter a review to classify it as Positive or Negative using a Hugging Face model."
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
# Launch app
|
| 29 |
+
if __name__ == "__main__":
|
| 30 |
+
iface.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
transformers
|
| 3 |
+
torch
|