Rubyando59 commited on
Commit
348d568
β€’
1 Parent(s): 041332b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -19
app.py CHANGED
@@ -37,7 +37,7 @@ def main():
37
  st.title("πŸ—Ό Lutece-Vision-Base Demo")
38
  st.markdown("Please keep in mind that inference might be slower since this Huggingface space is running on CPU only.")
39
 
40
- # Sidebar with SujetAI watermark
41
  st.sidebar.image("sujetAI.svg", use_column_width=True)
42
  st.sidebar.markdown("---")
43
  st.sidebar.markdown("Sujet AI, a Paris-based AI startup, is on a noble mission to democratize investment opportunities by leveraging built-in models and cutting-edge technologies. Committed to open-sourcing its technology, Sujet AI aims to contribute to the research and development communities, ultimately serving the greater good of humanity.")
@@ -47,30 +47,56 @@ def main():
47
  # Load model and processor
48
  model, processor = load_model_and_processor()
49
 
50
- # File uploader for document
51
- uploaded_file = st.file_uploader("πŸ“„ Upload a financial document", type=["png", "jpg", "jpeg"])
52
 
53
- if uploaded_file is not None:
54
- image = Image.open(uploaded_file).convert('RGB')
 
 
55
 
56
- # Two-column layout
57
- col1, col2 = st.columns(2)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
 
59
- with col1:
60
- # Display image with controlled size
61
- st.image(image, caption="Uploaded Document", use_column_width=True)
62
 
63
- with col2:
64
- # Question input
65
- question = st.text_input("❓ Ask a question about the document", "")
66
- submit_button = st.button("πŸ” Generate Answer")
67
 
68
- # Answer section spanning both columns
69
- if submit_button and question:
70
- with st.spinner("Generating answer..."):
71
- answer = generate_answer(model, processor, image, question)
72
- st.success(f"## πŸ’‘ {answer}")
73
 
 
 
 
 
 
 
 
 
 
74
 
75
  if __name__ == "__main__":
76
  main()
 
37
  st.title("πŸ—Ό Lutece-Vision-Base Demo")
38
  st.markdown("Please keep in mind that inference might be slower since this Huggingface space is running on CPU only.")
39
 
40
+ # Sidebar with SujetAI watermark
41
  st.sidebar.image("sujetAI.svg", use_column_width=True)
42
  st.sidebar.markdown("---")
43
  st.sidebar.markdown("Sujet AI, a Paris-based AI startup, is on a noble mission to democratize investment opportunities by leveraging built-in models and cutting-edge technologies. Committed to open-sourcing its technology, Sujet AI aims to contribute to the research and development communities, ultimately serving the greater good of humanity.")
 
47
  # Load model and processor
48
  model, processor = load_model_and_processor()
49
 
50
+ # Two-column layout
51
+ col1, col2 = st.columns(2)
52
 
53
+ with col1:
54
+ st.subheader("πŸ“„ Financial Document")
55
+ # Option to use example image or upload new one
56
+ use_example = st.checkbox("Use example image", value=True)
57
 
58
+ if use_example:
59
+ image = Image.open("test_image.png").convert('RGB')
60
+ st.image(image, caption="Example Document", use_column_width=True)
61
+ else:
62
+ uploaded_file = st.file_uploader("Upload a financial document", type=["png", "jpg", "jpeg"])
63
+ if uploaded_file is not None:
64
+ image = Image.open(uploaded_file).convert('RGB')
65
+ st.image(image, caption="Uploaded Document", use_column_width=True)
66
+ else:
67
+ image = None
68
+
69
+ with col2:
70
+ st.subheader("❓ Ask a Question")
71
+ # Predefined questions
72
+ example_questions = [
73
+ "What's the current expenses amount?",
74
+ "When was this document produced?",
75
+ "Who is this document addressed to?",
76
+ "What is the amount that's circled?",
77
+ "What's the project's identifier?"
78
+ ]
79
 
80
+ selected_question = st.selectbox("Select a question or type your own:",
81
+ [""] + example_questions,
82
+ index=0)
83
 
84
+ if selected_question:
85
+ question = selected_question
86
+ else:
87
+ question = st.text_input("Type your question here:")
88
 
89
+ submit_button = st.button("πŸ” Generate Answer")
 
 
 
 
90
 
91
+ # Answer section
92
+ if submit_button and question and image is not None:
93
+ with st.spinner("Generating answer..."):
94
+ answer = generate_answer(model, processor, image, question)
95
+ st.success(f"## πŸ’‘ {answer}")
96
+ elif submit_button and image is None:
97
+ st.warning("Please upload an image or use the example image before asking a question.")
98
+ elif submit_button and not question:
99
+ st.warning("Please enter a question or select one from the examples.")
100
 
101
  if __name__ == "__main__":
102
  main()