Update final_code.py
Browse files- final_code.py +67 -0
final_code.py
CHANGED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
# Function to get list of document IDs
|
| 6 |
+
def get_document_ids():
|
| 7 |
+
# Assuming 'abc' is the folder containing documents
|
| 8 |
+
document_ids = [file.split('_')[0] for file in os.listdir('abc') if file.endswith('.png')]
|
| 9 |
+
return list(set(document_ids))
|
| 10 |
+
|
| 11 |
+
# Function to load image based on selected document ID and page number
|
| 12 |
+
def load_image(document_id, page_number):
|
| 13 |
+
image_path = f'abc/{document_id}_{page_number}.png'
|
| 14 |
+
if os.path.exists(image_path):
|
| 15 |
+
return image_path
|
| 16 |
+
else:
|
| 17 |
+
return None
|
| 18 |
+
|
| 19 |
+
# Function to load dataframe based on selected document ID
|
| 20 |
+
def load_dataframe(document_id):
|
| 21 |
+
csv_path = f'abc/{document_id}_1.csv'
|
| 22 |
+
if os.path.exists(csv_path):
|
| 23 |
+
return pd.read_csv(csv_path)
|
| 24 |
+
else:
|
| 25 |
+
return None
|
| 26 |
+
|
| 27 |
+
def main():
|
| 28 |
+
st.set_page_config(layout="wide") # Set layout to wide
|
| 29 |
+
|
| 30 |
+
# Slider to adjust the width of the columns
|
| 31 |
+
col1_width = st.sidebar.slider("Width of First Column", 0.1, 10.0, 1.0, 0.1)
|
| 32 |
+
col2_width = st.sidebar.slider("Width of Second Column", 0.1, 10.0, 3.0, 0.1)
|
| 33 |
+
col3_width = st.sidebar.slider("Width of Third Column", 0.1, 10.0, 2.0, 0.1)
|
| 34 |
+
|
| 35 |
+
# Divide the screen into three vertical panels with specified widths
|
| 36 |
+
col1, col2, col3 = st.columns([col1_width, col2_width, col3_width])
|
| 37 |
+
|
| 38 |
+
# Document Selection Panel
|
| 39 |
+
with col1:
|
| 40 |
+
st.write("### Document Selection")
|
| 41 |
+
document_id = st.selectbox("Select Document ID", options=get_document_ids())
|
| 42 |
+
page_number = st.number_input("Page Number", min_value=1, step=1, value=1)
|
| 43 |
+
|
| 44 |
+
# Display Image Panel
|
| 45 |
+
with col2:
|
| 46 |
+
st.write("### Display Image")
|
| 47 |
+
image_path = load_image(document_id, page_number)
|
| 48 |
+
if image_path:
|
| 49 |
+
st.image(image_path)
|
| 50 |
+
else:
|
| 51 |
+
st.write("Image not found")
|
| 52 |
+
|
| 53 |
+
# Display DataFrame Panel
|
| 54 |
+
with col3:
|
| 55 |
+
st.write("### Display DataFrame")
|
| 56 |
+
df = load_dataframe(document_id)
|
| 57 |
+
if df is not None:
|
| 58 |
+
columns_to_display = st.multiselect("Select Columns to Display", df.columns)
|
| 59 |
+
if len(columns_to_display) > 0:
|
| 60 |
+
st.write(df[columns_to_display])
|
| 61 |
+
else:
|
| 62 |
+
st.write("No columns selected")
|
| 63 |
+
else:
|
| 64 |
+
st.write("DataFrame not found")
|
| 65 |
+
|
| 66 |
+
if __name__ == "__main__":
|
| 67 |
+
main()
|