File size: 1,656 Bytes
7b1e257
bf265e0
 
 
 
d68f63a
0bc3e3d
 
d68f63a
0bc3e3d
d68f63a
 
bf265e0
 
d68f63a
7b1e257
 
bf265e0
7b1e257
bf265e0
 
 
7b1e257
bf265e0
 
7b1e257
bf265e0
7b1e257
 
bf265e0
43fcf3d
d68f63a
 
0bc3e3d
d68f63a
 
 
 
 
 
 
 
 
 
 
 
bf265e0
7b1e257
bf265e0
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
38
39
40
41
42
43
44
45
46
47
48
49
50
import streamlit as st
from transformers import pipeline, AutoConfig

MODEL_NAME = "blaikhole/distilbert-review-bug-classifier"

label_mapping = {
    "LABEL_0": "Graphics issue 🎨",
    "LABEL_1": "Network issue 🌐",
    "LABEL_2": "No Bug ✅",
    "LABEL_3": "Performance issue 🚀"
}

# Load model config to get label mapping
config = AutoConfig.from_pretrained(MODEL_NAME)
id2label = config.id2label

# Create a pipeline for text classification
pipe = pipeline("text-classification", model=MODEL_NAME)

# Streamlit app UI
st.title("Review Bug Classification Demo 🐞")
st.write("Enter some text and the model will predict the bug category.")

# User Input
user_input = st.text_area("Input Text:", height=150)

# Prediction
if st.button("Classify"):
    if user_input:
        result = pipe(user_input, return_all_scores=True)[0]  # Get all scores

        predictions = {label_mapping.get(res['label'], res['label']): int(res['score'] * 100) for res in result}
        
        ordered_labels = ["Graphics issue 🎨", "Network issue 🌐", "No Bug ✅", "Performance issue 🚀"]
        ordered_predictions = {k: predictions[k] for k in ordered_labels if k in predictions}

        # Get top prediction
        top_label = max(ordered_predictions, key=ordered_predictions.get)

        # Show top category
        st.write(f"### 🏆 Predicted Category: `{top_label}`")

        st.write("### Confidence Scores:")
        for label, score in ordered_predictions.items():
            st.write(f"**{label}**")
            st.progress(score)  # Display confidence as a progress bar

    else:
        st.warning("⚠️ Please enter some text.")