sahiba12 commited on
Commit
478a2de
·
1 Parent(s): 474e5a2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -0
app.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ from transformers import AutoTokenizer, TFAutoModelForSequenceClassification
4
+
5
+ HF_TOKEN = os.environ.get('HF_TOKEN')
6
+
7
+ model_checkpoint = "besijar/dspa_review_classification"
8
+ tokeniser = AutoTokenizer.from_pretrained(model_checkpoint, use_auth_token=HF_TOKEN)
9
+ model = TFAutoModelForSequenceClassification.from_pretrained(model_checkpoint, use_auth_token=HF_TOKEN)
10
+
11
+ 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."
12
+
13
+ def review_classify(review):
14
+ review = tokeniser.encode(review)
15
+ review = model.predict([review])
16
+ return int(review.logits.argmax())
17
+
18
+ iface = gr.Interface(review_classify,
19
+ title="Review Classification using DistilRoBERTa",
20
+ inputs=[gr.Text(label="Review")],
21
+ outputs=[gr.Number(label="Rating", precision=0)],
22
+ examples=[example_review])
23
+ iface.launch()