Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from transformers import pipeline | |
| import torch | |
| import random | |
| model = pipeline("text-classification", model="CPF3-org/cpf-poc-model") | |
| def analyze(text): | |
| result = model(text)[0] | |
| epsilon = 0.8 | |
| # CORREZIONE: usa random invece di torch.normal | |
| noise = random.gauss(0, epsilon / 10) | |
| noisy_score = result['score'] + noise | |
| label_map = {"LABEL_0": "green", "LABEL_1": "yellow", "LABEL_2": "red"} | |
| return { | |
| "vulnerability": result['label'].split("_")[-1].replace("LABEL_", ""), | |
| "severity": label_map[result['label']], | |
| "confidence": max(0, min(1, noisy_score)), | |
| "explanation": f"Detected CPF indicator {result['label'].split('_')[-1]}." | |
| } | |
| demo = gr.Interface(fn=analyze, inputs="text", outputs="json") | |
| demo.launch() |