Gokce commited on
Commit
addf4f0
·
1 Parent(s): 47e6db1

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+
5
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
6
+
7
+ tokenizer = AutoTokenizer.from_pretrained("Gokce/finetuned-distilbert-multi-rr")
8
+ model = AutoModelForSequenceClassification.from_pretrained("Gokce/finetuned-distilbert-multi-rr")
9
+
10
+
11
+ MAX_LENGTH = 128
12
+
13
+ def predict(text):
14
+ inputs = tokenizer.encode_plus(text, add_special_tokens=True, return_tensors="tf", padding=True, truncation=True, max_length=MAX_LENGTH)
15
+
16
+ predictions = model.predict([inputs['input_ids'], inputs['attention_mask']])
17
+ predicted_class_idx = np.argmax(predictions[0])
18
+
19
+ if predicted_class_idx == 0:
20
+ predicted_class = "Human"
21
+ else:
22
+ predicted_class = "AI"
23
+
24
+ return predicted_class
25
+
26
+
27
+ iface = gr.Interface(
28
+ fn=predict,
29
+ inputs=gr.inputs.Textbox(lines=5, placeholder="Enter text...", label='Review Text'),
30
+ outputs=gr.outputs.Textbox(label='Detected Label'),
31
+ title='Generated Text Classifier for Restaurant Reviews'
32
+ )
33
+ iface.launch()
34
+
35
+
36
+