File size: 1,095 Bytes
4e7f9ec
a987c9c
81d6e67
c156409
 
a987c9c
4e7f9ec
81d6e67
8ae7827
a987c9c
81d6e67
5545fe9
a987c9c
8ae7827
 
81d6e67
 
8ae7827
 
81d6e67
a987c9c
 
 
8ae7827
a987c9c
81d6e67
8ae7827
81d6e67
 
5545fe9
81d6e67
8ae7827
 
 
 
 
5545fe9
81d6e67
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
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()