isurulkh commited on
Commit
205ccd3
1 Parent(s): 7e180af

Upload 3 files

Browse files
app.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from joblib import load
3
+ from sklearn.pipeline import Pipeline
4
+
5
+ # Load the pre-trained model
6
+ model: Pipeline = load('app/trained_intent_classifier.joblib')
7
+
8
+ def classify_intent(text, model, threshold=0.7):
9
+ # Predict the probability distribution over the classes
10
+ probs = model.predict_proba([text])[0]
11
+ # Get the maximum probability and its corresponding class
12
+ confidence = max(probs)
13
+ intent = model.classes_[probs.argmax()]
14
+
15
+ # Check if the confidence meets the threshold
16
+ if confidence < threshold:
17
+ return "NLU fallback: Intent could not be confidently determined"
18
+ else:
19
+ return f"Intent: {intent}, Confidence: {confidence:.2f}"
20
+
21
+ def main():
22
+ st.title("Intent Classification App")
23
+ st.write("""
24
+ This app uses a machine learning model to classify user intents based on the text they provide.
25
+ Simply enter some text below and click 'Classify' to see the predicted intent and confidence level.
26
+ """)
27
+
28
+ # Sidebar for settings
29
+ st.sidebar.title("Settings")
30
+ threshold = st.sidebar.slider("Confidence Threshold", 0.0, 1.0, 0.7, 0.01)
31
+ st.sidebar.write("Adjust the confidence threshold to classify intents.")
32
+
33
+ # User input in the main area
34
+ user_input = st.text_area("Enter your text here:", height=150)
35
+
36
+ if st.button("Classify"):
37
+ if user_input:
38
+ # Classify the intent
39
+ result = classify_intent(user_input, model, threshold=threshold)
40
+ st.success(f"Classified as: {result}")
41
+ else:
42
+ st.error("Please enter some text to classify.")
43
+
44
+ if __name__ == "__main__":
45
+ main()
app/trained_intent_classifier.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:601050c7eec5b5672448b300dbc4e5bad71b6421e4ed6c15ad60906bf1a9cc13
3
+ size 30421
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ numpy
2
+ pandas
3
+ scikit-learn
4
+ streamlit
5
+ joblib