saghir608/Ai_Scam_Detector
0
1import gradio as gr2from core.scam_detector import analyze_scam3 4 5# Backend function6def analyze_input(text, url, file):7 8 result = analyze_scam(text=text, url=url, file=file)9 10 return f"""11<div class="result-box">12 <div class="risk-score">Risk Score: {result['risk']}%</div>13 <div class="status">{result['status']}</div>14 <div class="reason">{result['reason']}</div>15</div>16"""17 18 19# Custom HTML + CSS20custom_css = """21body {22 background-color: #f4f6f8;23}24 25.container {26 max-width: 800px;27 margin: auto;28 padding: 20px;29}30 31.title {32 text-align: center;33 font-size: 36px;34 font-weight: bold;35 margin-bottom: 5px;36}37 38.subtitle {39 text-align: center;40 color: gray;41 margin-bottom: 20px;42}43 44.analyze-btn {45 background-color: #2563eb;46 color: white;47 font-size: 18px;48 padding: 12px;49 border-radius: 8px;50}51 52.result-box {53 background: white;54 padding: 20px;55 border-radius: 10px;56 margin-top: 20px;57 border-left: 5px solid red;58}59 60.risk-score {61 font-size: 24px;62 font-weight: bold;63}64 65.status {66 font-size: 18px;67 margin-top: 10px;68}69 70.reason {71 color: gray;72 margin-top: 10px;73}74"""75 76 77# UI Layout78with gr.Blocks(css=custom_css, title="AI Scam Checker") as app:79 80 gr.HTML("""81 <div class="container">82 <div class="title">๐ก๏ธ AI Scam Checker</div>83 <div class="subtitle">84 Detect scam links, messages, and files instantly85 </div>86 </div>87 """)88 89 with gr.Tabs():90 91 with gr.Tab("Text"):92 text_input = gr.Textbox(93 placeholder="Paste suspicious message...",94 lines=5,95 show_label=False96 )97 98 with gr.Tab("URL"):99 url_input = gr.Textbox(100 placeholder="Enter suspicious URL...",101 show_label=False102 )103 104 with gr.Tab("File"):105 file_input = gr.File(106 label="Upload file"107 )108 109 analyze_btn = gr.Button(110 "๐ Analyze",111 elem_classes="analyze-btn"112 )113 114 result_output = gr.HTML()115 116 analyze_btn.click(117 analyze_input,118 inputs=[text_input, url_input, file_input],119 outputs=result_output120 )121 122 123app.launch()