pratikshahp commited on
Commit
beccc93
·
verified ·
1 Parent(s): a5efddc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -23
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", 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
- submit = st.button("Generate Response")
54
-
55
- if submit:
56
- if image is None:
57
- st.warning("Please upload an image.")
58
- else:
59
- extracted_text = extract_text_from_image(image)
60
- response = get_response_from_llm(extracted_text, question)
61
- st.subheader("Extracted Information")
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)