File size: 1,121 Bytes
8444252
efb9e6f
8444252
 
 
efb9e6f
8444252
 
 
efb9e6f
8444252
efb9e6f
8444252
 
 
 
efb9e6f
8444252
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import os
import gradio as gr
from transformers import AutoTokenizer, TFAutoModelForSequenceClassification

HF_TOKEN = os.environ.get('HF_TOKEN')

model_checkpoint = "besijar/dspa_review_classification"
tokeniser = AutoTokenizer.from_pretrained(model_checkpoint, use_auth_token=HF_TOKEN)
model = TFAutoModelForSequenceClassification.from_pretrained(model_checkpoint, use_auth_token=HF_TOKEN)

example_review = "Tully's House Blend is the perfect K-Cup for me.  Sure, I occasionally enjoy the special flavors.....Mocha, Italian roast, French vanilla, but my favorite 'go-to'coffee is House Blend. Wakes me up in the morning with it's coffee house full hearty taste."

def review_classify(review):
    review = tokeniser.encode(review)
    review = model.predict([review])
    return int(review.logits.argmax())

iface = gr.Interface(review_classify,
                        title="Review Classification using DistilRoBERTa",
                        inputs=[gr.Text(label="Review")],
                        outputs=[gr.Number(label="Rating", precision=0)],
                        examples=[example_review])
iface.launch()