deepugaur commited on
Commit
fae5744
·
verified ·
1 Parent(s): 23ddfce

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -24
app.py CHANGED
@@ -57,33 +57,33 @@ def lime_explain(prompt, model, tokenizer, max_length=100):
57
 
58
  # Load Model Section
59
  st.subheader("Load Your Trained Model")
60
- model_path = st.text_input("Enter the path to your trained model (.h5):")
61
  model = None
62
  tokenizer = None
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
 
64
- if model_path:
65
- try:
66
- model = load_model(model_path)
67
- tokenizer = setup_tokenizer()
68
- st.success("Model Loaded Successfully!")
69
-
70
- # User Prompt Input
71
- st.subheader("Classify Your Prompt")
72
- user_prompt = st.text_input("Enter a prompt to classify:")
73
-
74
- if user_prompt:
75
- class_label, confidence_score = detect_prompt(user_prompt, tokenizer, model)
76
- st.write(f"Predicted Class: **{class_label}**")
77
- st.write(f"Confidence Score: **{confidence_score:.2f}%**")
78
-
79
- # LIME Explanation
80
- st.subheader("LIME Explanation")
81
- explanation = lime_explain(user_prompt, model, tokenizer)
82
- explanation_as_html = explanation.as_html()
83
- st.components.v1.html(explanation_as_html, height=500)
84
-
85
- except Exception as e:
86
- st.error(f"Error Loading Model: {e}")
87
 
88
  # Footer
89
  st.write("---")
 
57
 
58
  # Load Model Section
59
  st.subheader("Load Your Trained Model")
 
60
  model = None
61
  tokenizer = None
62
+ model_path = "deep_learning_model.h5" # Ensure this file is in the same directory as app.py
63
+
64
+ try:
65
+ model = load_model(model_path)
66
+ tokenizer = setup_tokenizer()
67
+ st.success("Model Loaded Successfully!")
68
+
69
+ # User Prompt Input
70
+ st.subheader("Classify Your Prompt")
71
+ user_prompt = st.text_input("Enter a prompt to classify:")
72
+
73
+ if user_prompt:
74
+ class_label, confidence_score = detect_prompt(user_prompt, tokenizer, model)
75
+ st.write(f"Predicted Class: **{class_label}**")
76
+ st.write(f"Confidence Score: **{confidence_score:.2f}%**")
77
+
78
+ # LIME Explanation
79
+ st.subheader("LIME Explanation")
80
+ explanation = lime_explain(user_prompt, model, tokenizer)
81
+ explanation_as_html = explanation.as_html()
82
+ st.components.v1.html(explanation_as_html, height=500)
83
+
84
+ except Exception as e:
85
+ st.error(f"Error Loading Model: {e}")
86
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
 
88
  # Footer
89
  st.write("---")