|
print("first test for hugging face") |
|
import gradio as gr |
|
from transformers import AutoTokenizer, AutoModelForSequenceClassification |
|
import torch |
|
|
|
|
|
tokenizer = AutoTokenizer.from_pretrained("Remicm/sentiment-analysis-model-for-socialmedia") |
|
model = AutoModelForSequenceClassification.from_pretrained("Remicm/sentiment-analysis-model-for-socialmedia") |
|
|
|
|
|
def predict_sentiment(text): |
|
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True) |
|
with torch.no_grad(): |
|
outputs = model(**inputs) |
|
logits = outputs.logits |
|
predicted_class = torch.argmax(logits, dim=1).item() |
|
|
|
|
|
sentiments = ["Negative", "Neutral", "Positive"] |
|
return sentiments[predicted_class] |
|
|
|
|
|
interface = gr.Interface(fn=predict_sentiment, |
|
inputs="text", |
|
outputs="label", |
|
title="Sentiment Analysis of Instagram Comments", |
|
description="Enter a comment to determine its sentiment (Positive, Neutral, Negative).") |
|
|
|
|
|
interface.launch() |
|
|