Spaces:
Sleeping
Sleeping
| 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() | |