Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,17 +1,30 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
# Load your model with full label scoring
|
| 5 |
model = "VerifiedPrompts/CNTXT-Filter-Prompt-Opt"
|
| 6 |
classifier = pipeline("text-classification", model=model, return_all_scores=True)
|
| 7 |
|
| 8 |
def classify(prompt):
|
| 9 |
-
results = classifier(prompt)[0]
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
# Gradio UI
|
| 15 |
demo = gr.Interface(
|
| 16 |
fn=classify,
|
| 17 |
inputs="textbox",
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
|
|
|
| 4 |
model = "VerifiedPrompts/CNTXT-Filter-Prompt-Opt"
|
| 5 |
classifier = pipeline("text-classification", model=model, return_all_scores=True)
|
| 6 |
|
| 7 |
def classify(prompt):
|
| 8 |
+
results = classifier(prompt)[0]
|
| 9 |
+
|
| 10 |
+
# Map model labels to readable names
|
| 11 |
+
label_map = {
|
| 12 |
+
"LABEL_0": "Intent is unclear, Please input more context",
|
| 13 |
+
"LABEL_1": "has context",
|
| 14 |
+
"LABEL_2": "missing platform, audience, budget, goal"
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
# Convert list of label-score dicts into a usable dict
|
| 18 |
+
score_dict = {r["label"]: r["score"] for r in results}
|
| 19 |
+
|
| 20 |
+
# 🔒 Priority logic: if label_0 score > 0, block it
|
| 21 |
+
if score_dict["LABEL_0"] > 0:
|
| 22 |
+
return "Intent is unclear"
|
| 23 |
+
|
| 24 |
+
# Otherwise, return the top label
|
| 25 |
+
top_label = max(results, key=lambda r: r["score"])["label"]
|
| 26 |
+
return label_map[top_label]
|
| 27 |
|
|
|
|
| 28 |
demo = gr.Interface(
|
| 29 |
fn=classify,
|
| 30 |
inputs="textbox",
|