Update app.py
Browse files
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 |
-
|
| 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 |
-
#
|
| 51 |
-
|
| 52 |
|
| 53 |
-
|
| 54 |
-
|
|
|
|
|
|
|
| 55 |
|
| 56 |
-
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
|
| 68 |
-
|
| 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()
|