Spaces:
Runtime error
Runtime error
import streamlit as st | |
import json | |
import base64 | |
# Chargeons un fichier JSON contenant les données | |
try: | |
with open("resources.json", "r", encoding='utf-8') as file: | |
resources = json.load(file) | |
except Exception as e: | |
st.error(f"Erreur lors du chargement du fichier JSON : {e}") | |
resources = [] | |
# Définissons la fonction create_card | |
def create_card(emoji, title, description, url): | |
with st.container(): | |
col1, col2 = st.columns([1, 5]) | |
with col1: | |
st.markdown(f"<h1 style='text-align: center; color: #4caf50;'>{emoji}</h1>", unsafe_allow_html=True) | |
with col2: | |
st.subheader(title) | |
st.write(description) | |
st.link_button("Ouvrir " + title, url, help=None, type="secondary", disabled=False, use_container_width=True) | |
st.divider() | |
# Base64 encoding function for images | |
def get_image_as_base64(path): | |
with open(path, "rb") as image_file: | |
return base64.b64encode(image_file.read()).decode() | |
# Load image and get base64 | |
image_path = "EDUCA.png" | |
image_base64 = get_image_as_base64(image_path) | |
# Display the image with rounded corners | |
st.markdown( | |
f'<img src="data:image/png;base64,{image_base64}" style="border-radius: 10px; width: 100%;">', | |
unsafe_allow_html=True | |
) | |
# Affichage d'un titre pour l'application et d'une barre de recherche | |
st.title("🏫 Ressources de EDUCA") | |
search_query = st.text_input("🔍 Recherche", "") | |
# Filtre les ressources basé sur la recherche | |
filtered_resources = [res for res in resources if search_query.lower() in res["Nom"].lower() or search_query.lower() in res["Description"].lower()] | |
# Créons les tabs | |
tab_all, tab_spaces, tab_models, tab_datasets = st.tabs(["✨ Tout", "🚀 Espaces", "📼 Modèles", "📁 Datasets"]) | |
# Fonction pour afficher les ressources filtrées dans chaque onglet | |
def show_resources(filtered_resources, category): | |
displayed_resources = [res for res in filtered_resources if res["Categorie"] == category] | |
if displayed_resources: | |
for res in displayed_resources: | |
create_card(res["Emoji"], res["Nom"], res["Description"], res["Url"]) | |
else: | |
st.error("🔴 Rien pour le moment.") | |
# Tab Tout | |
with tab_all: | |
st.header("Toutes les ressources") | |
if filtered_resources: | |
for res in filtered_resources: | |
create_card(res["Emoji"], res["Nom"], res["Description"], res["Url"]) | |
else: | |
st.error("🔴 Aucune ressource ne correspond à votre recherche.") | |
# Tabs pour chaque catégorie avec les ressources filtrées | |
with tab_spaces: | |
st.header("Espaces") | |
show_resources(filtered_resources, "Space") | |
with tab_models: | |
st.header("Modèles") | |
show_resources(filtered_resources, "Model") | |
with tab_datasets: | |
st.header("Datasets") | |
show_resources(filtered_resources, "Dataset") | |