Spaces:
Running
Running
File size: 1,432 Bytes
b60ab7a b641578 b304261 bed7dc7 b641578 a0402f7 b304261 a0402f7 b60ab7a b304261 b641578 b304261 a0402f7 b304261 1d4b61c b304261 a0402f7 b304261 a0402f7 b304261 a0402f7 b641578 a0402f7 b304261 a0402f7 b641578 1d4b61c | 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 45 46 | import os
import gradio as gr
from arabguard.core import ArabGuard
# إعداد ArabGuard فقط
guard = ArabGuard(use_ai=True)
def universal_api(user_input, system_prompt):
"""
الدالة دي هدفها الفحص فقط وترجيع الـ Trace للباك إند
"""
# 1. فحص ArabGuard
result = guard.analyze(user_input)
steps = result.pipeline_steps
# 2. هنرجع نتيجة الفحص والقرار (Blocked أو Safe)
# مش هنكلم Groq هنا لأن الباك إند هو اللي هيكلمه بناءً على القرار ده
decision = result.decision # ده بيرجع Label (SAFE/BLOCKED)
# بنرجع رد مؤقت، الـ Steps، والقرار
return "Analysis Complete", steps, decision
# الواجهة (بقت أخف بكتير)
with gr.Blocks() as demo:
gr.Markdown("# ArabGuard Analyzer Gateway")
with gr.Row():
sys_in = gr.Textbox(label="System Prompt", value="أنت مساعد ذكي.")
usr_in = gr.Textbox(label="User Input")
run_btn = gr.Button("Analyze")
with gr.Row():
out_msg = gr.Textbox(label="Status Message")
out_status = gr.Label(label="Security Decision")
out_json = gr.JSON(label="ArabGuard Trace")
run_btn.click(
universal_api,
inputs=[usr_in, sys_in],
outputs=[out_msg, out_json, out_status]
)
demo.launch() |