File size: 1,964 Bytes
8cb27aa
 
 
 
 
 
 
 
 
 
dc8b11f
 
 
 
 
8cb27aa
 
 
ee24ba8
8cb27aa
 
90c301f
8cb27aa
 
 
 
 
 
 
 
dc8b11f
8cb27aa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import os
from streamlit_pdf_viewer import pdf_viewer

# Define the base directory where the folders are located
BASE_DIR = "./brevet"

# Utility function to list files for a given subject and type
def get_files(subject, file_type):
    subject_path = os.path.join(BASE_DIR, subject)
    # Adjust to remove '.pdf' from filenames
    if file_type == 'Corrigé':
        files = [f.replace(' Corrigé.pdf', '') for f in os.listdir(subject_path) if 'Corrigé' in f]
    else:
        files = [f.replace('.pdf', '') for f in os.listdir(subject_path) if 'Corrigé' not in f and f.endswith('.pdf')]
    return sorted(files, reverse=True)

# Streamlit app layout
st.title("Sujets et Corrigés du Brevet (*Par Studyrama*)")

# Subject selection
subject = st.selectbox("Sélectionner la matière", ["Francais", "Mathématique", "Science", "Histoire-Géographie-EMC"])

# File type selection (Sujet or Corrigé)
file_type = st.selectbox("Sélectionner le type", ["Sujet", "Corrigé"])

# Year and File selection based on the subject and file type
files = get_files(subject, file_type)
selected_file = st.selectbox("Sélectionner l'année", files)

file_name = f"{selected_file}{' Corrigé' if file_type == 'Corrigé' else ''}.pdf"
file_path = os.path.join(BASE_DIR, subject, file_name)

# Initialize or update session state for button press
if 'show_pdf' not in st.session_state:
    st.session_state.show_pdf = False

# Create columns for the PDF viewer and download button
col1, col2 = st.columns(2)

with col1:
    if st.button(f"Afficher {file_type}"):
        st.session_state.show_pdf = True

if st.session_state.show_pdf:
    pdf_viewer(file_path, width=700)  # Adjust width as needed

with col2:
    with open(file_path, "rb") as pdf_file:
        st.download_button(label=f"Télécharger {file_type}",
                           data=pdf_file,
                           file_name=file_name,
                           mime="application/pdf")