Spaces:
Runtime error
Runtime error
fix: file_upload uses BytesIO
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ import torch
|
|
| 2 |
import streamlit as st
|
| 3 |
|
| 4 |
from PIL import Image
|
|
|
|
| 5 |
from transformers import VisionEncoderDecoderModel, VisionEncoderDecoderConfig , DonutProcessor
|
| 6 |
|
| 7 |
|
|
@@ -50,6 +51,17 @@ def run_prediction(sample):
|
|
| 50 |
|
| 51 |
task_prompt = f"<s>"
|
| 52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
st.text('''
|
| 54 |
This is OCR-free Document Understanding Transformer nicknamed 🍩. It was fine-tuned with 1000 receipt images -> SROIE dataset.
|
| 55 |
The original 🍩 implementation can be found on: https://github.com/clovaai/donut
|
|
@@ -59,7 +71,7 @@ image_upload = None
|
|
| 59 |
with st.sidebar:
|
| 60 |
information = st.radio(
|
| 61 |
"What information inside the are you interested in?",
|
| 62 |
-
('Receipt Summary', 'Receipt Menu Details', 'Extract all
|
| 63 |
receipt = st.selectbox('Pick one 🧾', ['1', '2', '3', '4', '5', '6'], index=1)
|
| 64 |
|
| 65 |
# file upload
|
|
@@ -67,7 +79,7 @@ with st.sidebar:
|
|
| 67 |
if uploaded_file is not None:
|
| 68 |
# To read file as bytes:
|
| 69 |
image_bytes_data = uploaded_file.getvalue()
|
| 70 |
-
image_upload = Image.open(image_bytes_data) #.frombytes('RGBA', (128,128), image_bytes_data, 'raw')
|
| 71 |
# st.write(bytes_data)
|
| 72 |
|
| 73 |
st.text(f'{information} mode is ON!\nTarget 🧾: {receipt}') # \n(opening image @:./img/receipt-{receipt}.png)')
|
|
|
|
| 2 |
import streamlit as st
|
| 3 |
|
| 4 |
from PIL import Image
|
| 5 |
+
from io import BytesIO
|
| 6 |
from transformers import VisionEncoderDecoderModel, VisionEncoderDecoderConfig , DonutProcessor
|
| 7 |
|
| 8 |
|
|
|
|
| 51 |
|
| 52 |
task_prompt = f"<s>"
|
| 53 |
|
| 54 |
+
st.markdown("""
|
| 55 |
+
<h3 align="center">
|
| 56 |
+
<img
|
| 57 |
+
src="https://https://huggingface.co/spaces/unstructuredio/receipt-parser/tree/main/img/unstructured_logo.png"
|
| 58 |
+
height="200"
|
| 59 |
+
>
|
| 60 |
+
</h3>
|
| 61 |
+
|
| 62 |
+
<div align="center">
|
| 63 |
+
""")
|
| 64 |
+
|
| 65 |
st.text('''
|
| 66 |
This is OCR-free Document Understanding Transformer nicknamed 🍩. It was fine-tuned with 1000 receipt images -> SROIE dataset.
|
| 67 |
The original 🍩 implementation can be found on: https://github.com/clovaai/donut
|
|
|
|
| 71 |
with st.sidebar:
|
| 72 |
information = st.radio(
|
| 73 |
"What information inside the are you interested in?",
|
| 74 |
+
('Receipt Summary', 'Receipt Menu Details', 'Extract all'))
|
| 75 |
receipt = st.selectbox('Pick one 🧾', ['1', '2', '3', '4', '5', '6'], index=1)
|
| 76 |
|
| 77 |
# file upload
|
|
|
|
| 79 |
if uploaded_file is not None:
|
| 80 |
# To read file as bytes:
|
| 81 |
image_bytes_data = uploaded_file.getvalue()
|
| 82 |
+
image_upload = Image.open(BytesIO(image_bytes_data)) #.frombytes('RGBA', (128,128), image_bytes_data, 'raw')
|
| 83 |
# st.write(bytes_data)
|
| 84 |
|
| 85 |
st.text(f'{information} mode is ON!\nTarget 🧾: {receipt}') # \n(opening image @:./img/receipt-{receipt}.png)')
|