Spaces:
Sleeping
Sleeping
João Pedro
commited on
Commit
·
fd98f6f
1
Parent(s):
506a3d8
only accept one file upload at a time
Browse files
app.py
CHANGED
@@ -10,34 +10,34 @@ model = LayoutLMv3ForTokenClassification.from_pretrained("microsoft/layoutlmv3-b
|
|
10 |
st.title("Document Classification with LayoutLMv3")
|
11 |
|
12 |
# File uploader for PDFs, JPGs, and PNGs
|
13 |
-
|
14 |
"Upload Document", type=["pdf", "jpg", "png"], accept_multiple_files=False
|
15 |
)
|
16 |
|
17 |
-
if
|
18 |
-
for uploaded_file in uploaded_files:
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
|
32 |
-
|
33 |
-
|
34 |
|
35 |
-
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
|
|
38 |
)
|
39 |
-
|
40 |
-
correct_label = st.text_input(
|
41 |
-
"Please provide the correct label:"
|
42 |
-
)
|
43 |
-
# Here you can implement logic to store or process feedback
|
|
|
10 |
st.title("Document Classification with LayoutLMv3")
|
11 |
|
12 |
# File uploader for PDFs, JPGs, and PNGs
|
13 |
+
uploaded_file = st.file_uploader(
|
14 |
"Upload Document", type=["pdf", "jpg", "png"], accept_multiple_files=False
|
15 |
)
|
16 |
|
17 |
+
if uploaded_file:
|
18 |
+
# for uploaded_file in uploaded_files:
|
19 |
+
if uploaded_file.type == "application/pdf":
|
20 |
+
images = convert_from_path(uploaded_file)
|
21 |
+
else:
|
22 |
+
images = [Image.open(uploaded_file)]
|
23 |
|
24 |
+
# Process each image for classification
|
25 |
+
for i, image in enumerate(images):
|
26 |
+
st.image(image, caption=f'Uploaded Image {i}', use_column_width=True)
|
27 |
+
# Prepare image for model input
|
28 |
+
encoding = processor(image, return_tensors="pt")
|
29 |
+
outputs = model(**encoding)
|
30 |
+
predictions = outputs.logits.argmax(-1)
|
31 |
|
32 |
+
# Display predictions (you may want to map indices to labels)
|
33 |
+
st.write(f"Predictions: {predictions}")
|
34 |
|
35 |
+
# User feedback section
|
36 |
+
feedback = st.radio(
|
37 |
+
"Is the classification correct?", ("Yes", "No")
|
38 |
+
)
|
39 |
+
if feedback == "No":
|
40 |
+
correct_label = st.text_input(
|
41 |
+
"Please provide the correct label:"
|
42 |
)
|
43 |
+
# Here you can implement logic to store or process feedback
|
|
|
|
|
|
|
|