app improvement again and again
Browse files
app.py
CHANGED
|
@@ -14,6 +14,11 @@ st.set_page_config(
|
|
| 14 |
layout="wide"
|
| 15 |
)
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
# Custom CSS
|
| 19 |
st.markdown("""
|
|
@@ -99,7 +104,7 @@ with st.expander("📝 Example Inputs"):
|
|
| 99 |
if st.button("Use Example 1"):
|
| 100 |
st.session_state.user_input = "Have a great day!"
|
| 101 |
if st.button("Use Example 2"):
|
| 102 |
-
st.session_state.user_input = "
|
| 103 |
if st.button("Use Example 3"):
|
| 104 |
st.session_state.user_input = "You're amazing!"
|
| 105 |
|
|
@@ -148,26 +153,31 @@ if user_input:
|
|
| 148 |
st.error(f"Error: {error}")
|
| 149 |
else:
|
| 150 |
# Format probability as percentage
|
| 151 |
-
|
| 152 |
|
| 153 |
# Create prediction box with appropriate severity class
|
| 154 |
severity_class = get_severity_class(result['probability'])
|
| 155 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
st.markdown(f"""
|
| 157 |
<div class="prediction-box {severity_class}">
|
| 158 |
<h3>Analysis Results</h3>
|
| 159 |
-
<p><strong>Prediction:</strong> {
|
| 160 |
-
<p><strong>
|
| 161 |
</div>
|
| 162 |
""", unsafe_allow_html=True)
|
| 163 |
|
| 164 |
# Confidence meter using Plotly
|
| 165 |
fig = go.Figure(go.Indicator(
|
| 166 |
mode = "gauge+number",
|
| 167 |
-
value =
|
| 168 |
title = {'text': "Confidence Level"},
|
| 169 |
gauge = {
|
| 170 |
-
'axis': {'range': [0,
|
| 171 |
'bar': {'color': "darkblue"},
|
| 172 |
'steps': [
|
| 173 |
{'range': [0, 0.3], 'color': "lightgreen"},
|
|
@@ -183,8 +193,8 @@ if user_input:
|
|
| 183 |
st.session_state.history.append({
|
| 184 |
'timestamp': datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
| 185 |
'text': user_input,
|
| 186 |
-
'prediction':
|
| 187 |
-
'confidence':
|
| 188 |
})
|
| 189 |
|
| 190 |
# History Section
|
|
|
|
| 14 |
layout="wide"
|
| 15 |
)
|
| 16 |
|
| 17 |
+
# Initialize session state
|
| 18 |
+
if 'history' not in st.session_state:
|
| 19 |
+
st.session_state.history = []
|
| 20 |
+
if 'api_health' not in st.session_state:
|
| 21 |
+
st.session_state.api_health = None
|
| 22 |
|
| 23 |
# Custom CSS
|
| 24 |
st.markdown("""
|
|
|
|
| 104 |
if st.button("Use Example 1"):
|
| 105 |
st.session_state.user_input = "Have a great day!"
|
| 106 |
if st.button("Use Example 2"):
|
| 107 |
+
st.session_state.user_input = "You are the worst person in the world."
|
| 108 |
if st.button("Use Example 3"):
|
| 109 |
st.session_state.user_input = "You're amazing!"
|
| 110 |
|
|
|
|
| 153 |
st.error(f"Error: {error}")
|
| 154 |
else:
|
| 155 |
# Format probability as percentage
|
| 156 |
+
probability = result['probability']
|
| 157 |
|
| 158 |
# Create prediction box with appropriate severity class
|
| 159 |
severity_class = get_severity_class(result['probability'])
|
| 160 |
|
| 161 |
+
if result['prediction'] == 'offensive':
|
| 162 |
+
final_prediction = "Offensive"
|
| 163 |
+
else :
|
| 164 |
+
final_prediction = "Not Offensive"
|
| 165 |
+
|
| 166 |
st.markdown(f"""
|
| 167 |
<div class="prediction-box {severity_class}">
|
| 168 |
<h3>Analysis Results</h3>
|
| 169 |
+
<p><strong>Prediction:</strong> {final_prediction}</p>
|
| 170 |
+
<p><strong>Prediction Value:</strong> {probability:.2f}%</p>
|
| 171 |
</div>
|
| 172 |
""", unsafe_allow_html=True)
|
| 173 |
|
| 174 |
# Confidence meter using Plotly
|
| 175 |
fig = go.Figure(go.Indicator(
|
| 176 |
mode = "gauge+number",
|
| 177 |
+
value = probability,
|
| 178 |
title = {'text': "Confidence Level"},
|
| 179 |
gauge = {
|
| 180 |
+
'axis': {'range': [0, 1]},
|
| 181 |
'bar': {'color': "darkblue"},
|
| 182 |
'steps': [
|
| 183 |
{'range': [0, 0.3], 'color': "lightgreen"},
|
|
|
|
| 193 |
st.session_state.history.append({
|
| 194 |
'timestamp': datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
| 195 |
'text': user_input,
|
| 196 |
+
'prediction': final_prediction,
|
| 197 |
+
'confidence': probability
|
| 198 |
})
|
| 199 |
|
| 200 |
# History Section
|