Guhanselvam commited on
Commit
c9f7418
·
verified ·
1 Parent(s): 384f818

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +28 -0
  2. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from transformers import DistilBertTokenizer, DistilBertForSequenceClassification
4
+
5
+ # Load the model and tokenizer
6
+ model_name = "AventIQ-AI/distilbert-base-uncased-sentiment-analysis"
7
+ tokenizer = DistilBertTokenizer.from_pretrained(model_name)
8
+ model = DistilBertForSequenceClassification.from_pretrained(model_name)
9
+
10
+ def predict_sentiment(text):
11
+ inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True, max_length=512)
12
+ with torch.no_grad():
13
+ logits = model(**inputs).logits
14
+ predicted_class_id = torch.argmax(logits, dim=-1).item()
15
+ sentiment = "Positive" if predicted_class_id == 1 else "Negative"
16
+ return sentiment
17
+
18
+ # Create Gradio interface
19
+ iface = gr.Interface(
20
+ fn=predict_sentiment,
21
+ inputs=gr.Textbox(lines=3, placeholder="Enter text for sentiment analysis..."),
22
+ outputs=gr.Textbox(label="Sentiment"),
23
+ title="DistilBERT Sentiment Analysis",
24
+ description="Enter a sentence to classify its sentiment as Positive or Negative using a fine-tuned DistilBERT model.",
25
+ )
26
+
27
+ if __name__ == "__main__":
28
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ torch
2
+ transformers
3
+ sentencepiece
4
+ gradio