Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from joblib import load
|
| 3 |
+
|
| 4 |
+
# Load the vectorizer and model
|
| 5 |
+
vectorizer = load('tfidf_vectorizer.pkl')
|
| 6 |
+
model = load('fake_review_detector.pkl')
|
| 7 |
+
|
| 8 |
+
# Prediction function
|
| 9 |
+
def predict_review(review):
|
| 10 |
+
# Transform the input text into TF-IDF
|
| 11 |
+
review_tfidf = vectorizer.transform([review])
|
| 12 |
+
# Make a prediction
|
| 13 |
+
prediction = model.predict(review_tfidf)[0]
|
| 14 |
+
# Return the result
|
| 15 |
+
return "THIS IS NOT FAKE" if prediction == 0 else "THIS IS FAKE"
|
| 16 |
+
|
| 17 |
+
# Gradio interface
|
| 18 |
+
interface = gr.Interface(
|
| 19 |
+
fn=predict_review,
|
| 20 |
+
inputs="text",
|
| 21 |
+
outputs="text",
|
| 22 |
+
title="Fake Review Detector",
|
| 23 |
+
description="Type a review below to determine if it is fake or not."
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
# Launch the interface
|
| 27 |
+
interface.launch()
|