Spaces:
Sleeping
Sleeping
victor
commited on
Commit
·
0b983db
1
Parent(s):
1f8f6b8
new code
Browse files
app.py
CHANGED
@@ -1,14 +1,14 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
3 |
import torch
|
4 |
-
import
|
5 |
|
6 |
-
#
|
7 |
-
model_path =
|
8 |
-
model = AutoModelForSequenceClassification.from_pretrained(model_path, local_files_only=True)
|
9 |
-
tokenizer = AutoTokenizer.from_pretrained(model_path, local_files_only=True)
|
10 |
|
|
|
|
|
11 |
|
|
|
|
|
12 |
|
13 |
# Define the inference function
|
14 |
def predict_sentiment(text):
|
@@ -19,10 +19,9 @@ def predict_sentiment(text):
|
|
19 |
return label_map[predicted_label]
|
20 |
|
21 |
# Gradio interface set-up
|
|
|
22 |
title = "Movie Review Sentiment Analysis"
|
23 |
-
description = ("Enter a movie review and find out whether it's Positive or Negative!
|
24 |
-
"The fine-tuned distilbert-base-uncased model trained on the imdb dataset will try to classify your review.\n\n"
|
25 |
-
"Below are some examples you can try!")
|
26 |
review = gr.Textbox(lines=10, label="Enter your movie review here...")
|
27 |
prediction = gr.Textbox(label="Sentiment Label (Prediction)")
|
28 |
examples = [
|
@@ -31,15 +30,11 @@ examples = [
|
|
31 |
["Absolutely loved it! One of the best movies of all time"]
|
32 |
]
|
33 |
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
outputs=prediction,
|
41 |
-
examples=examples
|
42 |
-
)
|
43 |
|
44 |
-
|
45 |
-
intf.launch(inline=False)
|
|
|
|
|
|
|
1 |
import torch
|
2 |
+
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
3 |
|
4 |
+
# Define the local model path
|
5 |
+
model_path = "./review_analysis/output"
|
|
|
|
|
6 |
|
7 |
+
# Load the tokenizer
|
8 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
9 |
|
10 |
+
# Load the model directly from the local path
|
11 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_path)
|
12 |
|
13 |
# Define the inference function
|
14 |
def predict_sentiment(text):
|
|
|
19 |
return label_map[predicted_label]
|
20 |
|
21 |
# Gradio interface set-up
|
22 |
+
import gradio as gr
|
23 |
title = "Movie Review Sentiment Analysis"
|
24 |
+
description = ("Enter a movie review and find out whether it's Positive or Negative!")
|
|
|
|
|
25 |
review = gr.Textbox(lines=10, label="Enter your movie review here...")
|
26 |
prediction = gr.Textbox(label="Sentiment Label (Prediction)")
|
27 |
examples = [
|
|
|
30 |
["Absolutely loved it! One of the best movies of all time"]
|
31 |
]
|
32 |
|
33 |
+
intf = gr.Interface(fn=predict_sentiment,
|
34 |
+
title=title,
|
35 |
+
description=description,
|
36 |
+
inputs=review,
|
37 |
+
outputs=prediction,
|
38 |
+
examples=examples)
|
|
|
|
|
|
|
39 |
|
40 |
+
intf.launch(inline=False)
|
|