|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import streamlit as st
|
|
|
import os
|
|
|
from PIL import Image
|
|
|
import cv2
|
|
|
import pytesseract
|
|
|
from docx import Document
|
|
|
from pptx import Presentation
|
|
|
from io import BytesIO
|
|
|
import base64
|
|
|
from zipfile import ZipFile
|
|
|
import pandas as pd
|
|
|
|
|
|
|
|
|
|
|
|
UPLOAD_FOLDER = 'data/'
|
|
|
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
|
|
|
|
|
|
|
|
|
def login():
|
|
|
st.sidebar.subheader("Login")
|
|
|
username = st.sidebar.text_input("Username")
|
|
|
password = st.sidebar.text_input("Password", type="password")
|
|
|
if st.sidebar.button("Login"):
|
|
|
if username == "admin" and password == "secret":
|
|
|
st.session_state.logged_in = True
|
|
|
st.sidebar.success("You are logged in!")
|
|
|
st.rerun()
|
|
|
else:
|
|
|
st.sidebar.error("Invalid credentials.")
|
|
|
|
|
|
|
|
|
def logout():
|
|
|
if st.sidebar.button("Logout"):
|
|
|
st.session_state.logged_in = False
|
|
|
st.sidebar.success("You have been logged out!")
|
|
|
st.rerun()
|
|
|
|
|
|
|
|
|
def upload_files():
|
|
|
st.subheader("Upload Files")
|
|
|
uploaded_files = st.file_uploader("Choose files", type=["pdf", "docx", "pptx", "jpg", "png", "txt"], accept_multiple_files=True)
|
|
|
if uploaded_files:
|
|
|
for uploaded_file in uploaded_files:
|
|
|
file_path = os.path.join(UPLOAD_FOLDER, uploaded_file.name)
|
|
|
with open(file_path, "wb") as f:
|
|
|
f.write(uploaded_file.getbuffer())
|
|
|
st.success(f"✅ {uploaded_file.name} uploaded successfully!")
|
|
|
st.rerun()
|
|
|
|
|
|
|
|
|
def manage_files():
|
|
|
st.subheader("Manage Files")
|
|
|
files = os.listdir(UPLOAD_FOLDER)
|
|
|
|
|
|
if files:
|
|
|
|
|
|
file_data = []
|
|
|
for file in files:
|
|
|
file_path = os.path.join(UPLOAD_FOLDER, file)
|
|
|
file_size = os.path.getsize(file_path) / 1024
|
|
|
file_type = file.split(".")[-1].upper()
|
|
|
file_data.append({"File Name": file, "Type": file_type, "Size (KB)": round(file_size, 2)})
|
|
|
|
|
|
df = pd.DataFrame(file_data)
|
|
|
|
|
|
|
|
|
st.dataframe(df, use_container_width=True)
|
|
|
|
|
|
|
|
|
selected_file = st.selectbox("Select a file to manage", files)
|
|
|
col1, col2 = st.columns(2)
|
|
|
with col1:
|
|
|
if st.button("Delete Selected File"):
|
|
|
os.remove(os.path.join(UPLOAD_FOLDER, selected_file))
|
|
|
st.error(f"❌ {selected_file} deleted successfully!")
|
|
|
st.rerun()
|
|
|
with col2:
|
|
|
with open(os.path.join(UPLOAD_FOLDER, selected_file), "rb") as f:
|
|
|
st.download_button(
|
|
|
label="Download Selected File",
|
|
|
data=f,
|
|
|
file_name=selected_file,
|
|
|
mime="application/octet-stream"
|
|
|
)
|
|
|
else:
|
|
|
st.info("No files uploaded yet.")
|
|
|
|
|
|
|
|
|
def main():
|
|
|
st.title("Admin Panel")
|
|
|
|
|
|
|
|
|
if "logged_in" not in st.session_state:
|
|
|
st.session_state.logged_in = False
|
|
|
|
|
|
|
|
|
if not st.session_state.logged_in:
|
|
|
login()
|
|
|
st.stop()
|
|
|
|
|
|
|
|
|
logout()
|
|
|
|
|
|
|
|
|
upload_files()
|
|
|
|
|
|
|
|
|
manage_files()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
main()
|
|
|
|