Spaces:
Running
Running
Uncommented commented out app
Browse files
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 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 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 |
|