codingcoolfun9ed's picture
Update app.py
5e99838 verified
raw
history blame
1.16 kB
import gradio as gr
import sys
import os
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from api.predict import predict_review
def predict_api(text):
try:
if not text or len(text.strip()) == 0:
return {
"error": "text cannot be empty",
"prediction": None,
"confidence": 0.0,
"is_fake": False
}
result = predict_review(text)
return {
"prediction": result['prediction'],
"confidence": result['confidence'],
"is_fake": result['is_fake']
}
except Exception as e:
return {
"error": str(e),
"prediction": None,
"confidence": 0.0,
"is_fake": False
}
demo = gr.Interface(
fn=predict_api,
inputs=gr.Textbox(label="review text", lines=5, placeholder="enter review text here..."),
outputs=gr.JSON(label="result"),
title="sentinelcheck api",
description="check if review is fake or real",
api_name="predict"
)
if __name__ == "__main__":
demo.launch()