File size: 1,228 Bytes
8c28dd0
2f9bd26
8c28dd0
2f9bd26
8c28dd0
2f9bd26
8c28dd0
2f9bd26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
print("first test for hugging face")
import gradio as gr
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch

# Load the tokenizer and model
tokenizer = AutoTokenizer.from_pretrained("Remicm/sentiment-analysis-model-for-socialmedia")
model = AutoModelForSequenceClassification.from_pretrained("Remicm/sentiment-analysis-model-for-socialmedia")

# Function to predict sentiment
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()
    
    # Define sentiment labels (adjust based on your model's output)
    sentiments = ["Negative", "Neutral", "Positive"]
    return sentiments[predicted_class]

# Create the Gradio interface
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).")

# Launch the interface
interface.launch()