Download app.py from Gokce/Generated_text_Classifier_for_RestaurantReviewsTR: direct link, hf CLI and curl.
- Browser
- Download file 1.1 kB
-
https://huggingface.co/spaces/Gokce/Generated_text_Classifier_for_RestaurantReviewsTR/resolve/main/app.py
- Command line
-
hf download hf://spaces/Gokce/Generated_text_Classifier_for_RestaurantReviewsTR/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Gokce/Generated_text_Classifier_for_RestaurantReviewsTR/resolve/main/app.py
1.1 kB
| 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() | |