pratikshahp commited on
Commit
1fb09ab
·
verified ·
1 Parent(s): cdb8924

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -19
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.header("Invoice Extractor")
38
 
39
- uploaded_file = st.file_uploader("Upload an invoice image...", type=["jpg"])
40
- question = st.text_input("Enter your question about the invoice:")
41
- image = None
 
 
 
 
42
 
43
  if uploaded_file is not None:
44
- image = Image.open(uploaded_file)
45
- st.image(image, caption="Uploaded Image.", use_column_width=True)
46
-
47
- submit = st.button("Extract Information")
48
-
49
- if submit:
50
- if image is None:
51
- st.warning("Please upload an image.")
52
- else:
53
- extracted_text = extract_text_from_image(image)
54
- response = get_response_from_llm(extracted_text, question)
55
- st.subheader("Extracted Information:")
56
- st.write(response)
 
 
 
 
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)