Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
#gr.Interface.load("models/hipnologo/gpt2-imdb-finetune").launch()
|
|
|
3 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
4 |
|
5 |
def predict_review(text):
|
@@ -20,7 +21,19 @@ def predict_review(text):
|
|
20 |
# getting the predicted class
|
21 |
predicted_class = logits.argmax(-1).item()
|
22 |
|
23 |
-
|
|
|
|
|
|
|
|
|
24 |
|
25 |
-
iface = gr.Interface(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
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):
|
|
|
21 |
# getting the predicted class
|
22 |
predicted_class = logits.argmax(-1).item()
|
23 |
|
24 |
+
sentiment = 'Positive' if predicted_class == 1 else 'Negative'
|
25 |
+
|
26 |
+
# Create a Markdown string for the output
|
27 |
+
result_md = f"## Sentiment: **{sentiment}**"
|
28 |
+
return result_md
|
29 |
|
30 |
+
iface = gr.Interface(
|
31 |
+
fn=predict_review,
|
32 |
+
inputs=gr.inputs.Textbox(lines=7, placeholder="Enter text here..."),
|
33 |
+
outputs=gr.outputs.Markdown(),
|
34 |
+
title="Sentiment Analysis",
|
35 |
+
description="This application predicts the sentiment (Positive/Negative) of the input text using a fine-tuned GPT-2 model.",
|
36 |
+
theme="compact" # change this to the theme you prefer: 'huggingface', 'default'
|
37 |
+
)
|
38 |
iface.launch()
|
39 |
+
|