File size: 1,155 Bytes
5e99838
487fb9f
5e99838
487fb9f
 
5e99838
02c45ef
5e99838
c985b4c
5e99838
 
 
 
 
 
 
c985b4c
5e99838
c985b4c
5e99838
c985b4c
 
5e99838
 
c985b4c
 
5e99838
 
 
 
 
 
 
 
 
 
 
 
 
 
 
02c45ef
5e99838
 
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
39
40
41
42
43
44
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()