Spaces:
Sleeping
Sleeping
File size: 1,079 Bytes
4e3aa2b 3833645 4e3aa2b 3833645 8d6f754 4e3aa2b 3833645 2bbb75b 4e3aa2b 3833645 4e3aa2b 3833645 |
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 |
import gradio as gr
from transformers import pipeline
model = "VerifiedPrompts/CNTXT-Filter-Prompt-Opt"
classifier = pipeline("text-classification", model=model, return_all_scores=True)
def classify(prompt):
results = classifier(prompt)[0]
# Map model labels to readable names
label_map = {
"LABEL_0": "Intent is unclear, Please input more context",
"LABEL_1": "has context",
"LABEL_2": "missing platform, audience, budget, goal"
}
# Convert list of label-score dicts into a usable dict
score_dict = {r["label"]: r["score"] for r in results}
# 🔒 Priority logic: if label_0 score > 0, block it
if score_dict["LABEL_0"] > 0:
return "Intent is unclear"
# Otherwise, return the top label
top_label = max(results, key=lambda r: r["score"])["label"]
return label_map[top_label]
demo = gr.Interface(
fn=classify,
inputs="textbox",
outputs="text",
title="Prompt Context Classifier",
description="Classifies prompts as clear, vague, or missing structural context."
)
demo.launch()
|