hipnologo commited on
Commit
ddf50b1
1 Parent(s): d0c8cff

Update app.py

Browse files

Added label description

Files changed (1) hide show
  1. app.py +19 -11
app.py CHANGED
@@ -1,15 +1,23 @@
1
  import gradio as gr
2
  #gr.Interface.load("models/hipnologo/gpt2-imdb-finetune").launch()
3
 
4
- def postprocess_label(model, inp):
5
- result = model(inp)
6
- if result == "LABEL_0":
7
- return "Negative"
8
- elif result == "LABEL_1":
9
- return "Positive"
10
- else:
11
- return "Unknown label"
12
-
13
- iface = gr.Interface.load("models/hipnologo/gpt2-imdb-finetune")
14
- iface.fn = lambda inp: postprocess_label(iface.fn, inp)
 
 
 
 
 
 
 
 
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()