Upload app.py
Browse filesRevised commit
app.py
CHANGED
@@ -32,6 +32,8 @@ checkpoint_1 = "Highway/SubCat"
|
|
32 |
|
33 |
checkpoint_2 = "Highway/ExtraOver"
|
34 |
|
|
|
|
|
35 |
|
36 |
@st.cache(allow_output_mutation=True)
|
37 |
def load_model_1():
|
@@ -53,6 +55,16 @@ def load_tokenizer_2():
|
|
53 |
return AutoTokenizer.from_pretrained(checkpoint_2)
|
54 |
|
55 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
st.set_page_config(
|
57 |
page_title="Cost Data Classifier", layout= "wide", initial_sidebar_state="auto", page_icon="π·"
|
58 |
)
|
@@ -160,7 +172,7 @@ if submitted:
|
|
160 |
),
|
161 |
autosize=False,
|
162 |
width=800,
|
163 |
-
height=
|
164 |
xaxis_title="Likelihood of SubCatName",
|
165 |
yaxis_title="SubCatNames",
|
166 |
# legend_title="Topics"
|
@@ -247,3 +259,73 @@ if submitted:
|
|
247 |
Prediction_confidence_2 = st.metric("Prediction confidence", (str(round(sorted_preds_2[0][1]*100, 1))+"%"))
|
248 |
|
249 |
st.success("Great! ExtraOver successfully predicted. ", icon="β
")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
checkpoint_2 = "Highway/ExtraOver"
|
34 |
|
35 |
+
checkpoint_3 = "Highway/Conversion"
|
36 |
+
|
37 |
|
38 |
@st.cache(allow_output_mutation=True)
|
39 |
def load_model_1():
|
|
|
55 |
return AutoTokenizer.from_pretrained(checkpoint_2)
|
56 |
|
57 |
|
58 |
+
@st.cache(allow_output_mutation=True)
|
59 |
+
def load_model_3():
|
60 |
+
return AutoModelForSequenceClassification.from_pretrained(checkpoint_3)
|
61 |
+
|
62 |
+
|
63 |
+
@st.cache(allow_output_mutation=True)
|
64 |
+
def load_tokenizer_3():
|
65 |
+
return AutoTokenizer.from_pretrained(checkpoint_3)
|
66 |
+
|
67 |
+
|
68 |
st.set_page_config(
|
69 |
page_title="Cost Data Classifier", layout= "wide", initial_sidebar_state="auto", page_icon="π·"
|
70 |
)
|
|
|
172 |
),
|
173 |
autosize=False,
|
174 |
width=800,
|
175 |
+
height=500,
|
176 |
xaxis_title="Likelihood of SubCatName",
|
177 |
yaxis_title="SubCatNames",
|
178 |
# legend_title="Topics"
|
|
|
259 |
Prediction_confidence_2 = st.metric("Prediction confidence", (str(round(sorted_preds_2[0][1]*100, 1))+"%"))
|
260 |
|
261 |
st.success("Great! ExtraOver successfully predicted. ", icon="β
")
|
262 |
+
|
263 |
+
|
264 |
+
|
265 |
+
# Third prediction
|
266 |
+
|
267 |
+
label_list_3 = ['0.04', '0.045', '0.05', '0.1', '0.15', '0.2', '1.0', '7.0', '166.67', 'Others']
|
268 |
+
|
269 |
+
joined_clean_sents = prep_text(Text_entry)
|
270 |
+
|
271 |
+
# tokenize
|
272 |
+
tokenizer_3 = load_tokenizer_3()
|
273 |
+
tokenized_text_3 = tokenizer_3(joined_clean_sents, return_tensors="pt")
|
274 |
+
|
275 |
+
# predict
|
276 |
+
model_3 = load_model_3()
|
277 |
+
text_logits_3 = model_3(**tokenized_text_3).logits
|
278 |
+
predictions_3 = torch.softmax(text_logits_3, dim=1).tolist()[0]
|
279 |
+
predictions_3 = [round(a_, 3) for a_ in predictions_3]
|
280 |
+
|
281 |
+
# dictionary with label as key and percentage as value
|
282 |
+
pred_dict_3 = (dict(zip(label_list_3, predictions_3)))
|
283 |
+
|
284 |
+
# sort 'pred_dict' by value and index the highest at [0]
|
285 |
+
sorted_preds_3 = sorted(pred_dict_3.items(), key=lambda x: x[1], reverse=True)
|
286 |
+
|
287 |
+
# Make dataframe for plotly bar chart
|
288 |
+
u_3, v_3 = zip(*sorted_preds_3)
|
289 |
+
x_3 = list(u_3)
|
290 |
+
y_3 = list(v_3)
|
291 |
+
df4 = pd.DataFrame()
|
292 |
+
df4['Conversion_factor'] = x_3
|
293 |
+
df4['Likelihood'] = y_3
|
294 |
+
|
295 |
+
e1, e2, e3 = st.columns([1.5, 0.5, 1])
|
296 |
+
|
297 |
+
with e1:
|
298 |
+
st.header("Conversion_factor")
|
299 |
+
# plot graph of predictions
|
300 |
+
fig = px.bar(df4, x="Likelihood", y="Conversion_factor", orientation="h")
|
301 |
+
|
302 |
+
fig.update_layout(
|
303 |
+
# barmode='stack',
|
304 |
+
template='ggplot2',
|
305 |
+
font=dict(
|
306 |
+
family="Arial",
|
307 |
+
size=14,
|
308 |
+
color="black"
|
309 |
+
),
|
310 |
+
autosize=False,
|
311 |
+
width=800,
|
312 |
+
height=800,
|
313 |
+
xaxis_title="Likelihood of Conversion_factor",
|
314 |
+
yaxis_title="Conversion_factor",
|
315 |
+
# legend_title="Topics"
|
316 |
+
)
|
317 |
+
|
318 |
+
fig.update_xaxes(tickangle=0, tickfont=dict(family='Arial', color='black', size=14))
|
319 |
+
fig.update_yaxes(tickangle=0, tickfont=dict(family='Arial', color='black', size=14))
|
320 |
+
fig.update_annotations(font_size=14) # this changes y_axis, x_axis and subplot title font sizes
|
321 |
+
|
322 |
+
# Plot
|
323 |
+
st.plotly_chart(fig, use_container_width=False)
|
324 |
+
|
325 |
+
with e3:
|
326 |
+
st.header("")
|
327 |
+
predicted_3 = st.metric("Predicted ExtraOver", sorted_preds_3[0][0])
|
328 |
+
Prediction_confidence_3 = st.metric("Prediction confidence",
|
329 |
+
(str(round(sorted_preds_3[0][1] * 100, 1)) + "%"))
|
330 |
+
|
331 |
+
st.success("Great! Conversion_factor successfully predicted. ", icon="β
")
|