Spaces:
Running
Running
jl commited on
Commit ·
2b014b5
1
Parent(s): df8b9c1
add runtime
Browse files
app.py
CHANGED
|
@@ -4,6 +4,7 @@ import plotly.graph_objects as go
|
|
| 4 |
import plotly.express as px
|
| 5 |
import pandas as pd
|
| 6 |
import numpy as np
|
|
|
|
| 7 |
|
| 8 |
# Page configuration
|
| 9 |
st.set_page_config(
|
|
@@ -137,6 +138,7 @@ if classify_button:
|
|
| 137 |
if user_input.strip():
|
| 138 |
with st.spinner('🔄 Analyzing text...'):
|
| 139 |
# Get prediction
|
|
|
|
| 140 |
result = predict_hatespeech(
|
| 141 |
text=user_input,
|
| 142 |
rationale=optional_rationale if optional_rationale else None,
|
|
@@ -146,6 +148,7 @@ if classify_button:
|
|
| 146 |
config=config,
|
| 147 |
device=device
|
| 148 |
)
|
|
|
|
| 149 |
|
| 150 |
# Extract results
|
| 151 |
prediction = result['prediction']
|
|
@@ -153,6 +156,7 @@ if classify_button:
|
|
| 153 |
probabilities = result['probabilities']
|
| 154 |
rationale_scores = result['rationale_scores']
|
| 155 |
tokens = result['tokens']
|
|
|
|
| 156 |
|
| 157 |
# Display results
|
| 158 |
st.divider()
|
|
@@ -167,13 +171,15 @@ if classify_button:
|
|
| 167 |
unsafe_allow_html=True)
|
| 168 |
|
| 169 |
# Metrics
|
| 170 |
-
col1, col2, col3 = st.columns(
|
| 171 |
with col1:
|
| 172 |
st.metric("Confidence", f"{confidence:.1%}")
|
| 173 |
with col2:
|
| 174 |
st.metric("Not Hate Speech", f"{probabilities[0]:.1%}")
|
| 175 |
with col3:
|
| 176 |
st.metric("Hate Speech", f"{probabilities[1]:.1%}")
|
|
|
|
|
|
|
| 177 |
|
| 178 |
# Probability distribution chart
|
| 179 |
if show_probabilities:
|
|
|
|
| 4 |
import plotly.express as px
|
| 5 |
import pandas as pd
|
| 6 |
import numpy as np
|
| 7 |
+
import time
|
| 8 |
|
| 9 |
# Page configuration
|
| 10 |
st.set_page_config(
|
|
|
|
| 138 |
if user_input.strip():
|
| 139 |
with st.spinner('🔄 Analyzing text...'):
|
| 140 |
# Get prediction
|
| 141 |
+
start = time.time()
|
| 142 |
result = predict_hatespeech(
|
| 143 |
text=user_input,
|
| 144 |
rationale=optional_rationale if optional_rationale else None,
|
|
|
|
| 148 |
config=config,
|
| 149 |
device=device
|
| 150 |
)
|
| 151 |
+
end = time.time()
|
| 152 |
|
| 153 |
# Extract results
|
| 154 |
prediction = result['prediction']
|
|
|
|
| 156 |
probabilities = result['probabilities']
|
| 157 |
rationale_scores = result['rationale_scores']
|
| 158 |
tokens = result['tokens']
|
| 159 |
+
processing_time = end - start
|
| 160 |
|
| 161 |
# Display results
|
| 162 |
st.divider()
|
|
|
|
| 171 |
unsafe_allow_html=True)
|
| 172 |
|
| 173 |
# Metrics
|
| 174 |
+
col1, col2, col3, col4 = st.columns(4)
|
| 175 |
with col1:
|
| 176 |
st.metric("Confidence", f"{confidence:.1%}")
|
| 177 |
with col2:
|
| 178 |
st.metric("Not Hate Speech", f"{probabilities[0]:.1%}")
|
| 179 |
with col3:
|
| 180 |
st.metric("Hate Speech", f"{probabilities[1]:.1%}")
|
| 181 |
+
with col4:
|
| 182 |
+
st.metric("Processing Time", f"{processing_time:.3f}s")
|
| 183 |
|
| 184 |
# Probability distribution chart
|
| 185 |
if show_probabilities:
|