Update app.py
Browse files
app.py
CHANGED
|
@@ -2,9 +2,10 @@ import gradio as gr
|
|
| 2 |
from transformers import DistilBertTokenizer, DistilBertForSequenceClassification
|
| 3 |
import torch
|
| 4 |
|
| 5 |
-
# Load the
|
| 6 |
-
|
| 7 |
-
|
|
|
|
| 8 |
|
| 9 |
def predict_sentiment(text):
|
| 10 |
inputs = tokenizer(text, return_tensors="pt", padding="max_length", truncation=True, max_length=128)
|
|
@@ -15,7 +16,7 @@ def predict_sentiment(text):
|
|
| 15 |
sentiment = "positive" if predicted_class_id == 1 else "negative"
|
| 16 |
return sentiment
|
| 17 |
|
| 18 |
-
# Create a Gradio interface
|
| 19 |
demo = gr.Interface(
|
| 20 |
fn=predict_sentiment,
|
| 21 |
inputs=gr.Textbox(lines=5, placeholder="Enter text for sentiment analysis..."),
|
|
|
|
| 2 |
from transformers import DistilBertTokenizer, DistilBertForSequenceClassification
|
| 3 |
import torch
|
| 4 |
|
| 5 |
+
# ✅ Load the model from Hugging Face Hub
|
| 6 |
+
MODEL_NAME = "Kaiyeee/fine_tuned_distilbert_imdb" # Update this with your actual repo name
|
| 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="max_length", truncation=True, max_length=128)
|
|
|
|
| 16 |
sentiment = "positive" if predicted_class_id == 1 else "negative"
|
| 17 |
return sentiment
|
| 18 |
|
| 19 |
+
# ✅ Create a Gradio interface
|
| 20 |
demo = gr.Interface(
|
| 21 |
fn=predict_sentiment,
|
| 22 |
inputs=gr.Textbox(lines=5, placeholder="Enter text for sentiment analysis..."),
|