Spaces:
Runtime error
Runtime error
Update app.py
Browse filesAdded label description
app.py
CHANGED
@@ -1,15 +1,23 @@
|
|
1 |
import gradio as gr
|
2 |
#gr.Interface.load("models/hipnologo/gpt2-imdb-finetune").launch()
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
#gr.Interface.load("models/hipnologo/gpt2-imdb-finetune").launch()
|
3 |
|
4 |
+
import gradio as gr
|
5 |
+
from transformers import pipeline
|
6 |
+
|
7 |
+
# Load the sentiment analysis pipeline
|
8 |
+
sentiment_analysis = pipeline("text-classification", model="models/hipnologo/gpt2-imdb-finetune")
|
9 |
+
|
10 |
+
def predict(review_text):
|
11 |
+
# Run the review text through the pipeline
|
12 |
+
result = sentiment_analysis(review_text)[0]
|
13 |
+
|
14 |
+
# Map the LABEL_0/LABEL_1 to Negative/Positive
|
15 |
+
if result['label'] == 'LABEL_0':
|
16 |
+
result['label'] = 'Negative'
|
17 |
+
elif result['label'] == 'LABEL_1':
|
18 |
+
result['label'] = 'Positive'
|
19 |
+
|
20 |
+
return result['label'], float(result['score'])
|
21 |
+
|
22 |
+
iface = gr.Interface(fn=predict, inputs="textbox", outputs=["label", "number"])
|
23 |
iface.launch()
|