import os import spaces import gradio as gr from src.engine import DeepPragmaEngine from src.llm_client import GroqClient from src.knowledge_retriever import DogwhistleRetriever engine = DeepPragmaEngine() llm = GroqClient() if os.environ.get("GROQ_API_KEY") else None retriever = DogwhistleRetriever() @spaces.GPU def analyze(phrase): if not phrase.strip(): return "", "" if not llm: return "GROQ_API_KEY not configured", "" kb_matches = retriever.retrieve(phrase) result = llm.classify(phrase, kb_context=kb_matches) label = result["label"] reasoning = f"[Confidence: {result['confidence']}] {result['reasoning']}" return label, reasoning with gr.Blocks() as demo: gr.Markdown("# 🛡️ DeepPragma Classifier") input_box = gr.Textbox(label="Enter a sentence") button = gr.Button("Analyze") output_label = gr.Textbox(label="Classification") output_reasoning = gr.Textbox(label="Expert validation") button.click(analyze, input_box, [output_label, output_reasoning]) demo.launch()