File size: 1,097 Bytes
addf4f0 ed173b5 74163f1 addf4f0 1990b99 addf4f0 d1ff182 addf4f0 18102f5 addf4f0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | import gradio as gr
import transformers
import numpy as np
from transformers import DistilBertTokenizer, TFAutoModelForSequenceClassification
tokenizer = DistilBertTokenizer.from_pretrained("Gokce/finetuned_distilBERT_forDetecting_GeneratedReviews_TR")
model = TFAutoModelForSequenceClassification.from_pretrained("Gokce/finetuned_distilBERT_forDetecting_GeneratedReviews_TR")
MAX_LENGTH = 128
def predict(text):
inputs = tokenizer.encode_plus(text, add_special_tokens=True, return_tensors="tf", padding=True, truncation=True, max_length=MAX_LENGTH)
predictions = model.predict([inputs['input_ids'], inputs['attention_mask']])
predicted_class_idx = np.argmax(predictions[0])
if predicted_class_idx == 0:
predicted_class = "Human"
else:
predicted_class = "AI"
return predicted_class
iface = gr.Interface(
fn=predict,
inputs=gr.inputs.Textbox(lines=5, placeholder="Enter text...", label='Review Text'),
outputs=gr.outputs.Textbox(label='Detected Label'),
title='Generated Text Classifier for Restaurant Reviews'
)
iface.launch()
|