Spaces:
Sleeping
Sleeping
Store model components in session state and remove example analysis section
Browse files- app.py +3 -0
- pages/Analysis.py +0 -19
app.py
CHANGED
|
@@ -8,5 +8,8 @@ x = st.slider('Select a value')
|
|
| 8 |
st.write(x, 'squared is', x * x)
|
| 9 |
# load the model and cache it
|
| 10 |
model, label_encoder, tokenizer = load_model_for_prediction()
|
|
|
|
|
|
|
|
|
|
| 11 |
st.write('Model loaded')
|
| 12 |
|
|
|
|
| 8 |
st.write(x, 'squared is', x * x)
|
| 9 |
# load the model and cache it
|
| 10 |
model, label_encoder, tokenizer = load_model_for_prediction()
|
| 11 |
+
st.session_state['model'] = model
|
| 12 |
+
st.session_state['label_encoder'] = label_encoder
|
| 13 |
+
st.session_state['tokenizer'] = tokenizer
|
| 14 |
st.write('Model loaded')
|
| 15 |
|
pages/Analysis.py
CHANGED
|
@@ -76,25 +76,6 @@ def show_analysis():
|
|
| 76 |
else:
|
| 77 |
st.warning("Please enter some text to analyze.")
|
| 78 |
|
| 79 |
-
# Example Analysis Section
|
| 80 |
-
st.header("Example Analysis")
|
| 81 |
-
show_examples = st.checkbox("Show example analysis", key='show_examples')
|
| 82 |
-
|
| 83 |
-
if show_examples:
|
| 84 |
-
try:
|
| 85 |
-
df = pd.read_csv('data/raw/history_01.csv')
|
| 86 |
-
for sentence in df['Sentence'].head(5): # Limit to 5 examples
|
| 87 |
-
with st.container():
|
| 88 |
-
label, confidence = predict_sentence(
|
| 89 |
-
model, sentence, tokenizer, label_encoder
|
| 90 |
-
)
|
| 91 |
-
if label not in ("Unknown", "Error"):
|
| 92 |
-
st.write("---")
|
| 93 |
-
st.write(f"**Sentence:** {sentence}")
|
| 94 |
-
st.write(f"**Predicted:** {label}")
|
| 95 |
-
st.progress(confidence)
|
| 96 |
-
except FileNotFoundError:
|
| 97 |
-
st.warning("Example file not found. Please check the data path.")
|
| 98 |
|
| 99 |
except Exception as e:
|
| 100 |
st.error(f"Error: {str(e)}")
|
|
|
|
| 76 |
else:
|
| 77 |
st.warning("Please enter some text to analyze.")
|
| 78 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
|
| 80 |
except Exception as e:
|
| 81 |
st.error(f"Error: {str(e)}")
|