-
Notifications
You must be signed in to change notification settings - Fork 0
/
main4.py
75 lines (61 loc) · 2.88 KB
/
main4.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import streamlit as st
import pandas as pd
from PIL import Image
import ocr # assuming maintain.py is in the same directory
import outputter # assuming outputter.py is in the same directory
# Load the logo from the file
logo = Image.open('ptcl.png')
# Display the logo in the sidebar
st.sidebar.image(logo, use_column_width=False)
# Load the DataFrame from the CSV file
df = pd.read_csv('output.csv')
# Sidebar controls
st.sidebar.header('Controls')
run_ocr = st.sidebar.button('OCR', key='run_ocr')
generate_csv = st.sidebar.button('Generate CSV', key='generate_csv')
browse_images = st.sidebar.button('Browse for Images', key='browse_images')
show_comments = st.sidebar.checkbox('Comments', value=True, key='show_comments')
show_replies = st.sidebar.checkbox('Replies', value=True, key='show_replies')
show_time = st.sidebar.checkbox('Time', value=True, key='show_time')
# Run maintain.py when the OCR button is clicked
if run_ocr:
ocr.ocr() # assuming maintain.py has a function called run()
# Run outputter.py when the Generate CSV button is clicked
if generate_csv:
outputter.outputter() # assuming outputter.py has a function called run()
# Filter the DataFrame based on the checkboxes
if not show_comments:
df = df.loc[:, ~df.columns.str.contains('Comments')]
if not show_replies:
df = df.loc[:, ~df.columns.str.contains('Replies')]
if not show_time:
df = df.loc[:, ~df.columns.str.contains('Time')]
# Main DataFrame display
st.dataframe(df)
# Bottom page with logos and checkboxes
st.header('Select Groups')
# Define the networks and accounts
networks = ['Facebook', 'Twitter', 'Instagram', 'Linkedin']
accounts = ['Ufone', 'Upaisa', 'Corporate']
# Create a row of logos and checkboxes
logos_and_checkboxes = st.columns(len(networks))
checkboxes_dict = {}
for i, network in enumerate(networks):
logo = Image.open(f'C:\\Users\\jawad\\Downloads\\projects\\ocr\\images\\logos\\{network.lower()}.png')
logos_and_checkboxes[i].image(logo, use_column_width=False)
checkbox = logos_and_checkboxes[i].checkbox('', value=True, key=f'{network}_checkbox') # Added a unique key for each checkbox
checkboxes_dict[network] = checkbox
# Filter the DataFrame based on the checkboxes at the bottom
for network, checkbox in checkboxes_dict.items():
if not checkbox:
df = df.loc[:, ~df.columns.str.contains(network)]
# Create checkboxes for the accounts in the sidebar
st.sidebar.header('Select Accounts')
account_checkboxes_dict = {}
for account in accounts:
checkbox = st.sidebar.checkbox(account, value=True, key=f'{account}_checkbox') # Added a unique key for each checkbox
account_checkboxes_dict[account] = checkbox
# Filter the DataFrame based on the account checkboxes
for account, checkbox in account_checkboxes_dict.items():
if not checkbox:
df = df.loc[:, ~df.columns.str.contains(account)]