Update app.py
Browse files
app.py
CHANGED
@@ -33,27 +33,63 @@ def extract_text_from_pdf(pdf_file):
|
|
33 |
text += page.extract_text() or ""
|
34 |
return text
|
35 |
|
36 |
-
#
|
37 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
uploaded_file = st.file_uploader("Upload a PDF file", type="pdf")
|
40 |
|
41 |
if uploaded_file:
|
42 |
-
st.
|
43 |
document_text = extract_text_from_pdf(uploaded_file)
|
44 |
-
st.text_area("Extracted Text", document_text, height=
|
45 |
|
46 |
-
query = st.text_input("Enter your query")
|
47 |
|
48 |
-
if st.button("Get Answer"):
|
49 |
if query:
|
50 |
with st.spinner("Generating response..."):
|
51 |
response = generate_response_groq(document_text, query)
|
52 |
-
st.write("Response
|
53 |
st.write(response)
|
54 |
|
55 |
# Clear memory after generating response
|
56 |
gc.collect()
|
57 |
-
|
58 |
else:
|
59 |
st.error("Please enter a query.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
text += page.extract_text() or ""
|
34 |
return text
|
35 |
|
36 |
+
# Set the page layout to wide for better UI space
|
37 |
+
st.set_page_config(page_title="PDF Query Application", layout="wide")
|
38 |
+
|
39 |
+
# Sidebar
|
40 |
+
st.sidebar.title("PDF Query Assistant")
|
41 |
+
st.sidebar.image("https://upload.wikimedia.org/wikipedia/commons/thumb/a/af/PDF_file_icon.svg/1024px-PDF_file_icon.svg.png", use_column_width=True) # Adding an image in the sidebar
|
42 |
+
st.sidebar.markdown("### Navigation")
|
43 |
+
st.sidebar.markdown("Use this app to upload a PDF and ask questions about its content.")
|
44 |
+
st.sidebar.markdown("")
|
45 |
+
|
46 |
+
# Main UI layout
|
47 |
+
st.title("π PDF Query Application")
|
48 |
+
st.markdown("""
|
49 |
+
<style>
|
50 |
+
.main-content {background-color: #f0f2f6; padding: 20px; border-radius: 10px;}
|
51 |
+
.stButton>button {background-color: #4CAF50; color: white; font-size: 16px; border-radius: 10px;}
|
52 |
+
.stTextInput>div>div>input {background-color: #f0f2f6; color: black; border-radius: 5px;}
|
53 |
+
</style>
|
54 |
+
""", unsafe_allow_html=True)
|
55 |
+
|
56 |
+
st.markdown("<div class='main-content'>", unsafe_allow_html=True)
|
57 |
|
58 |
uploaded_file = st.file_uploader("Upload a PDF file", type="pdf")
|
59 |
|
60 |
if uploaded_file:
|
61 |
+
st.success("PDF uploaded successfully! π")
|
62 |
document_text = extract_text_from_pdf(uploaded_file)
|
63 |
+
st.text_area("π Extracted Text", document_text, height=200)
|
64 |
|
65 |
+
query = st.text_input("π Enter your query")
|
66 |
|
67 |
+
if st.button("π¬ Get Answer"):
|
68 |
if query:
|
69 |
with st.spinner("Generating response..."):
|
70 |
response = generate_response_groq(document_text, query)
|
71 |
+
st.write("**Response:**")
|
72 |
st.write(response)
|
73 |
|
74 |
# Clear memory after generating response
|
75 |
gc.collect()
|
|
|
76 |
else:
|
77 |
st.error("Please enter a query.")
|
78 |
+
|
79 |
+
st.markdown("</div>", unsafe_allow_html=True)
|
80 |
+
|
81 |
+
# Footer
|
82 |
+
st.sidebar.markdown("### About")
|
83 |
+
st.sidebar.info("Developed with β€οΈ using Streamlit and Groq API.")
|
84 |
+
st.sidebar.markdown("---")
|
85 |
+
st.sidebar.write("For more information, visit [Groq](https://www.groq.com) and [Streamlit](https://streamlit.io).")
|
86 |
+
|
87 |
+
# Customize the theme and color contrast
|
88 |
+
st.markdown("""
|
89 |
+
<style>
|
90 |
+
.css-1aumxhk {background-color: #E8EAF6;}
|
91 |
+
.stTextInput>div>div>input {border-color: #3f51b5;}
|
92 |
+
.stTextArea>div>div>textarea {border-color: #3f51b5;}
|
93 |
+
.stButton>button {background-color: #3f51b5; color: white; font-size: 16px;}
|
94 |
+
</style>
|
95 |
+
""", unsafe_allow_html=True)
|