Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,6 +5,7 @@ import torch
|
|
| 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,31 +33,25 @@ def get_response_from_llm(extracted_text, question):
|
|
| 32 |
return response
|
| 33 |
|
| 34 |
# Streamlit App
|
| 35 |
-
st.set_page_config(page_title="Invoice Extractor"
|
| 36 |
-
st.
|
| 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 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
st.write(response)
|
|
|
|
| 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 |
return response
|
| 34 |
|
| 35 |
# Streamlit App
|
| 36 |
+
st.set_page_config(page_title="Invoice Extractor")
|
| 37 |
+
st.header("Invoice Extractor")
|
| 38 |
|
| 39 |
# Sidebar for uploading image and entering question
|
| 40 |
st.sidebar.title("Upload Image and Enter Question")
|
| 41 |
uploaded_file = st.sidebar.file_uploader("Upload an invoice image...", type=["jpg", "jpeg", "png"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
if uploaded_file is not None:
|
| 43 |
+
image = Image.open(uploaded_file)
|
| 44 |
+
st.sidebar.image(image, caption="Uploaded Image.", use_column_width=True)
|
| 45 |
+
|
| 46 |
+
question = st.text_input("Enter your question about the invoice:")
|
| 47 |
+
image = None
|
| 48 |
+
submit = st.button("Generate Response")
|
| 49 |
+
|
| 50 |
+
if submit:
|
| 51 |
+
if image is None:
|
| 52 |
+
st.warning("Please upload an image.")
|
| 53 |
+
else:
|
| 54 |
+
extracted_text = extract_text_from_image(image)
|
| 55 |
+
response = get_response_from_llm(extracted_text, question)
|
| 56 |
+
st.subheader("Extracted Information:")
|
| 57 |
+
st.write(response)
|
|
|