Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,17 +1,27 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
#gr.Interface.load("models/hipnologo/gpt2-imdb-finetune").launch()
|
3 |
+
|
4 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
5 |
+
|
6 |
+
def predict_review(text):
|
7 |
+
# Specify the model name or path
|
8 |
+
model_name = "models/hipnologo/gpt2-imdb-finetune"
|
9 |
+
|
10 |
+
# Load your model and tokenizer
|
11 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
12 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
13 |
+
|
14 |
+
# encoding the input text
|
15 |
+
input_ids = tokenizer.encode(text, return_tensors="pt")
|
16 |
+
|
17 |
+
# getting the logits
|
18 |
+
output = model(input_ids)
|
19 |
+
logits = output.logits
|
20 |
+
|
21 |
+
# getting the predicted class
|
22 |
+
predicted_class = logits.argmax(-1).item()
|
23 |
+
|
24 |
+
return f"The sentiment predicted by the model is: {'Positive' if predicted_class == 1 else 'Negative'}"
|
25 |
+
|
26 |
+
iface = gr.Interface(fn=predict_review, inputs="textbox", outputs="text")
|
27 |
iface.launch()
|