VerifiedPrompts commited on
Commit
2bbb75b
·
verified ·
1 Parent(s): 8d6f754

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -6
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] # list of all label scores
10
- for r in results:
11
- print(f"{r['label']} {round(r['score'], 3)}") # optional log
12
- return "\n".join([f"{r['label']}: {round(r['score'], 3)}" for r in results])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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",