fsommers commited on
Commit
440913e
1 Parent(s): 0550ff1

Uncommented commented out app

Browse files
Files changed (1) hide show
  1. app.py +19 -21
app.py CHANGED
@@ -118,25 +118,23 @@ def predict(image, reader, processor: LayoutLMv3Processor, model: LayoutLMv3ForS
118
  probabilities = F.softmax(logits, dim=-1).flatten().tolist()
119
  return predicted_class.detach().item(), probabilities
120
 
121
- st.markdown(f"Test")
122
-
123
- # reader = create_ocr_reader()
124
- # processor = create_processor()
125
- # model = create_model()
126
-
127
- # uploaded_file = st.file_uploader("Choose a JPG file", ["jpg", "png"])
128
- # if uploaded_file is not None:
129
- # bytes_data = io.BytesIO(uploaded_file.read())
130
- # image = Image.open(bytes_data)
131
- # st.image(image, caption="Uploaded Image", use_column_width=True)
132
- # predicted, probabilities = predict(image, reader, processor, model)
133
- # predicted_label = model.config.id2label[predicted]
134
- # st.markdown(f"Predicted Label: {predicted_label}")
135
-
136
- # df = pd.DataFrame({
137
- # "Label": list(model.config.id2label.values()),
138
- # "Probability": probabilities
139
- # })
140
- # fig = px.bar(df, x="Label", y="Probability")
141
- # st.plotly_chart(fig, use_container_width=True)
142
 
 
118
  probabilities = F.softmax(logits, dim=-1).flatten().tolist()
119
  return predicted_class.detach().item(), probabilities
120
 
121
+ reader = create_ocr_reader()
122
+ processor = create_processor()
123
+ model = create_model()
124
+
125
+ uploaded_file = st.file_uploader("Choose a JPG file", ["jpg", "png"])
126
+ if uploaded_file is not None:
127
+ bytes_data = io.BytesIO(uploaded_file.read())
128
+ image = Image.open(bytes_data)
129
+ st.image(image, caption="Uploaded Image", use_column_width=True)
130
+ predicted, probabilities = predict(image, reader, processor, model)
131
+ predicted_label = model.config.id2label[predicted]
132
+ st.markdown(f"Predicted Label: {predicted_label}")
133
+
134
+ df = pd.DataFrame({
135
+ "Label": list(model.config.id2label.values()),
136
+ "Probability": probabilities
137
+ })
138
+ fig = px.bar(df, x="Label", y="Probability")
139
+ st.plotly_chart(fig, use_container_width=True)
 
 
140