ajeetkumar01 commited on
Commit
4c855d6
·
verified ·
1 Parent(s): 7ea50b6

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -0
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer
2
+ import gradio as gr
3
+
4
+ # Load model and tokenizer
5
+ model_name = "output/checkpoint-2500/"
6
+ model = AutoModelForSequenceClassification.from_pretrained(model_name)
7
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
8
+
9
+ # Define prediction function
10
+ def predict_sentiment(text):
11
+ inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True)
12
+ outputs = model(**inputs)
13
+ logits = outputs.logits
14
+ probabilities = logits.softmax(dim=1)
15
+ sentiment = "Positive" if probabilities[0][1] > 0.5 else "Negative"
16
+ return sentiment
17
+
18
+ # Create Gradio interface
19
+ text_input = gr.Textbox(lines=7, label="Input Text", placeholder="Enter your text here...")
20
+ output_text = gr.Textbox(label="Predicted Sentiment")
21
+
22
+ # Author information
23
+ author = "Ajeetkumar Ukande"
24
+
25
+ # Create Gradio interface
26
+ interface = gr.Interface(predict_sentiment, text_input, output_text,
27
+ title="<div style='color: #336699; font-size: 24px; font-weight: bold; border: 2px solid #336699; padding: 10px; border-radius: 10px;'>Sentiment-Analysis-FineTuned-DistilBERT</div>",
28
+ description=f"""<div style='color: #666666; font-family: Arial, sans-serif;'>
29
+ <p style='margin-top: 10px;'>This model predicts the sentiment of text.</p>
30
+ <p>It uses a fine-tuned DistilBERT model trained on IMDb movie reviews dataset.</p>
31
+ <p>The sentiment is classified as Positive if the probability of positive sentiment is greater than 0.5, otherwise it's classified as Negative.</p>
32
+ <p>Developed by <span style='color: #336699; font-weight: bold;'>{author}</span>.</p>
33
+ </div>""",
34
+ theme="huggingface",
35
+ allow_flagging=False,
36
+ )
37
+
38
+ interface.launch(share=True)