Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Use a pipeline as a high-level helper
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
import torch
|
| 4 |
+
import gradio as gr
|
| 5 |
+
import pandas as pd
|
| 6 |
+
|
| 7 |
+
#model_path = ("C:/Users/ankitdwivedi/OneDrive - Adobe/Desktop/NLP Projects/Video to Text Summarization/Model/models--distilbert--distilbert-base-uncased-finetuned-sst-2-english/snapshots/714eb0fa89d2f80546fda750413ed43d93601a13")
|
| 8 |
+
|
| 9 |
+
analyzer = pipeline("text-classification", model="distilbert/distilbert-base-uncased-finetuned-sst-2-english")
|
| 10 |
+
|
| 11 |
+
# print(analyzer(["This product is good", "This product is expensive"]))
|
| 12 |
+
|
| 13 |
+
def sentiment_analyzer(review):
|
| 14 |
+
sentiment = analyzer(review)
|
| 15 |
+
return sentiment[0]['label']
|
| 16 |
+
|
| 17 |
+
def Read_Analyze(file_object):
|
| 18 |
+
df = pd.read_csv(file_object, encoding='latin1')
|
| 19 |
+
|
| 20 |
+
if 'Review' not in df.columns:
|
| 21 |
+
raise ValueError("Review column not found")
|
| 22 |
+
df['Sentiment'] = df['Review'].apply(sentiment_analyzer)
|
| 23 |
+
return df
|
| 24 |
+
|
| 25 |
+
# result = sentiment_analyzer("C:/Users/ankitdwivedi/OneDrive - Adobe/Desktop/NLP Projects/Video to Text Summarization/Files/all-data.csv")
|
| 26 |
+
# print (result)
|
| 27 |
+
|
| 28 |
+
gr.close_all()
|
| 29 |
+
|
| 30 |
+
demo = gr.Interface(fn=Read_Analyze,
|
| 31 |
+
inputs=[gr.File(file_types = ["csv"],
|
| 32 |
+
label="Upload your review file")],outputs=[gr.Dataframe(label="Review")],
|
| 33 |
+
title="Project 3: Sentiment Analyzer",
|
| 34 |
+
description="""This is a Sentiment Analysis Model.""")
|
| 35 |
+
demo.launch()
|