ThePradip commited on
Commit
92f27ce
1 Parent(s): e1fd454

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -0
app.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import numpy as np
3
+ import gradio as gr
4
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
5
+
6
+ # Update this to the appropriate model
7
+ tokenizer = AutoTokenizer.from_pretrained("juliensimon/autonlp-imdb-demo-hf-16622775")
8
+ model = AutoModelForSequenceClassification.from_pretrained("juliensimon/autonlp-imdb-demo-hf-16622775")
9
+
10
+ def predict(review):
11
+ inputs = tokenizer(review, padding=True, truncation=True, return_tensors="pt")
12
+ outputs = model(**inputs)
13
+ predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
14
+ predictions = predictions.detach().numpy()[0]
15
+ index = np.argmax(predictions)
16
+ score = predictions[index]
17
+ return "This review is {:.2f}% {}".format(100*score, "negative" if index==0 else "positive")
18
+
19
+ iface = gr.Interface(fn=predict, inputs="text", outputs="text")
20
+ iface.launch()