Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,7 +5,6 @@ import torch
|
|
| 5 |
import easyocr
|
| 6 |
|
| 7 |
# Load the question-answering model and tokenizer
|
| 8 |
-
#model_name = "t5-base"
|
| 9 |
model_name = "google/flan-t5-base"
|
| 10 |
qa_model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
| 11 |
qa_tokenizer = AutoTokenizer.from_pretrained(model_name)
|
|
@@ -33,24 +32,31 @@ def get_response_from_llm(extracted_text, question):
|
|
| 33 |
return response
|
| 34 |
|
| 35 |
# Streamlit App
|
| 36 |
-
st.set_page_config(page_title="Invoice Extractor")
|
| 37 |
-
st.
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
image =
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
if uploaded_file is not None:
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
st.
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
import easyocr
|
| 6 |
|
| 7 |
# Load the question-answering model and tokenizer
|
|
|
|
| 8 |
model_name = "google/flan-t5-base"
|
| 9 |
qa_model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
| 10 |
qa_tokenizer = AutoTokenizer.from_pretrained(model_name)
|
|
|
|
| 32 |
return response
|
| 33 |
|
| 34 |
# Streamlit App
|
| 35 |
+
st.set_page_config(page_title="Invoice Extractor", layout="wide")
|
| 36 |
+
st.title("Invoice Extractor")
|
| 37 |
|
| 38 |
+
# Sidebar for uploading image and entering question
|
| 39 |
+
st.sidebar.title("Upload Image and Enter Question")
|
| 40 |
+
uploaded_file = st.sidebar.file_uploader("Upload an invoice image...", type=["jpg", "jpeg", "png"])
|
| 41 |
+
question = st.sidebar.text_input("Enter your question about the invoice:")
|
| 42 |
+
|
| 43 |
+
# Main content area
|
| 44 |
+
col1, col2 = st.columns([1, 3])
|
| 45 |
|
| 46 |
if uploaded_file is not None:
|
| 47 |
+
with col1:
|
| 48 |
+
st.subheader("Uploaded Image")
|
| 49 |
+
image = Image.open(uploaded_file)
|
| 50 |
+
st.image(image, caption="Uploaded Image", use_column_width=True)
|
| 51 |
+
|
| 52 |
+
with col2:
|
| 53 |
+
st.subheader("Extracted Information")
|
| 54 |
+
submit = st.button("Extract Information")
|
| 55 |
+
|
| 56 |
+
if submit:
|
| 57 |
+
if image is None:
|
| 58 |
+
st.warning("Please upload an image.")
|
| 59 |
+
else:
|
| 60 |
+
extracted_text = extract_text_from_image(image)
|
| 61 |
+
response = get_response_from_llm(extracted_text, question)
|
| 62 |
+
st.write(response)
|