Spaces:
Sleeping
Sleeping
João Pedro
commited on
Commit
·
63eb0c6
1
Parent(s):
392dd2d
remove unnecessary comments
Browse files
app.py
CHANGED
|
@@ -31,22 +31,19 @@ model = LayoutLMv3ForSequenceClassification.from_pretrained(
|
|
| 31 |
|
| 32 |
st.title("Document Classification with LayoutLMv3")
|
| 33 |
|
| 34 |
-
# File uploader for PDFs, JPGs, and PNGs
|
| 35 |
uploaded_file = st.file_uploader(
|
| 36 |
"Upload Document", type=["pdf", "jpg", "png"], accept_multiple_files=False
|
| 37 |
)
|
| 38 |
|
| 39 |
if uploaded_file:
|
| 40 |
-
# for uploaded_file in uploaded_files:
|
| 41 |
if uploaded_file.type == "application/pdf":
|
| 42 |
images = convert_from_bytes(uploaded_file.getvalue())
|
| 43 |
else:
|
| 44 |
images = [Image.open(uploaded_file)]
|
| 45 |
|
| 46 |
-
# Process each image for classification
|
| 47 |
for i, image in enumerate(images):
|
| 48 |
st.image(image, caption=f'Uploaded Image {i}', use_container_width=True)
|
| 49 |
-
|
| 50 |
encoding = processor(
|
| 51 |
image,
|
| 52 |
return_tensors="pt",
|
|
@@ -56,10 +53,8 @@ if uploaded_file:
|
|
| 56 |
outputs = model(**encoding)
|
| 57 |
prediction = outputs.logits.argmax(-1)[0].item()
|
| 58 |
|
| 59 |
-
# Display predictions (you may want to map indices to labels)
|
| 60 |
st.write(f"Prediction: {id2label[prediction]}")
|
| 61 |
|
| 62 |
-
# User feedback section
|
| 63 |
feedback = st.radio(
|
| 64 |
"Is the classification correct?", ("Yes", "No"),
|
| 65 |
key=f'prediction-{i}'
|
|
@@ -68,4 +63,3 @@ if uploaded_file:
|
|
| 68 |
correct_label = st.selectbox(
|
| 69 |
"Please select the correct label:", labels
|
| 70 |
)
|
| 71 |
-
# Here you can implement logic to store or process feedback
|
|
|
|
| 31 |
|
| 32 |
st.title("Document Classification with LayoutLMv3")
|
| 33 |
|
|
|
|
| 34 |
uploaded_file = st.file_uploader(
|
| 35 |
"Upload Document", type=["pdf", "jpg", "png"], accept_multiple_files=False
|
| 36 |
)
|
| 37 |
|
| 38 |
if uploaded_file:
|
|
|
|
| 39 |
if uploaded_file.type == "application/pdf":
|
| 40 |
images = convert_from_bytes(uploaded_file.getvalue())
|
| 41 |
else:
|
| 42 |
images = [Image.open(uploaded_file)]
|
| 43 |
|
|
|
|
| 44 |
for i, image in enumerate(images):
|
| 45 |
st.image(image, caption=f'Uploaded Image {i}', use_container_width=True)
|
| 46 |
+
|
| 47 |
encoding = processor(
|
| 48 |
image,
|
| 49 |
return_tensors="pt",
|
|
|
|
| 53 |
outputs = model(**encoding)
|
| 54 |
prediction = outputs.logits.argmax(-1)[0].item()
|
| 55 |
|
|
|
|
| 56 |
st.write(f"Prediction: {id2label[prediction]}")
|
| 57 |
|
|
|
|
| 58 |
feedback = st.radio(
|
| 59 |
"Is the classification correct?", ("Yes", "No"),
|
| 60 |
key=f'prediction-{i}'
|
|
|
|
| 63 |
correct_label = st.selectbox(
|
| 64 |
"Please select the correct label:", labels
|
| 65 |
)
|
|
|