Spaces:
Sleeping
Sleeping
muzamilhxmi
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -6,7 +6,7 @@ MODEL_NAME = "blaikhole/distilbert-review-bug-classifier"
|
|
6 |
|
7 |
# Load model config to get label mapping
|
8 |
config = AutoConfig.from_pretrained(MODEL_NAME)
|
9 |
-
id2label = config.id2label
|
10 |
|
11 |
# Create a pipeline for text classification
|
12 |
pipe = pipeline("text-classification", model=MODEL_NAME)
|
@@ -22,14 +22,13 @@ user_input = st.text_area("Input Text:", height=150)
|
|
22 |
if st.button("Classify"):
|
23 |
if user_input:
|
24 |
result = pipe(user_input, return_all_scores=True)[0] # Get all scores
|
25 |
-
|
26 |
# Convert "LABEL_n" to actual class names
|
27 |
predictions = {id2label[int(res['label'].replace('LABEL_', ''))]: res['score'] for res in result}
|
28 |
top_label = max(predictions, key=predictions.get)
|
29 |
|
30 |
-
#
|
31 |
-
st.write(f"### 🏆 Predicted Category: `{top_label}`")
|
32 |
st.json(predictions) # Show confidence scores
|
33 |
else:
|
34 |
st.warning("⚠️ Please enter some text.")
|
35 |
-
|
|
|
6 |
|
7 |
# Load model config to get label mapping
|
8 |
config = AutoConfig.from_pretrained(MODEL_NAME)
|
9 |
+
id2label = config.id2label # Example: {0: "Bug", 1: "Feature Request", 2: "Documentation"}
|
10 |
|
11 |
# Create a pipeline for text classification
|
12 |
pipe = pipeline("text-classification", model=MODEL_NAME)
|
|
|
22 |
if st.button("Classify"):
|
23 |
if user_input:
|
24 |
result = pipe(user_input, return_all_scores=True)[0] # Get all scores
|
25 |
+
|
26 |
# Convert "LABEL_n" to actual class names
|
27 |
predictions = {id2label[int(res['label'].replace('LABEL_', ''))]: res['score'] for res in result}
|
28 |
top_label = max(predictions, key=predictions.get)
|
29 |
|
30 |
+
# Show decoded label
|
31 |
+
st.write(f"### 🏆 Predicted Category: `{top_label}`})")
|
32 |
st.json(predictions) # Show confidence scores
|
33 |
else:
|
34 |
st.warning("⚠️ Please enter some text.")
|
|