Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import json
|
| 3 |
+
import base64
|
| 4 |
+
|
| 5 |
+
# Chargeons un fichier JSON contenant les données
|
| 6 |
+
try:
|
| 7 |
+
with open("resources.json", "r", encoding='utf-8') as file:
|
| 8 |
+
resources = json.load(file)
|
| 9 |
+
except Exception as e:
|
| 10 |
+
st.error(f"Erreur lors du chargement du fichier JSON : {e}")
|
| 11 |
+
resources = []
|
| 12 |
+
|
| 13 |
+
# Définissons la fonction create_card
|
| 14 |
+
def create_card(emoji, title, description, url):
|
| 15 |
+
with st.container():
|
| 16 |
+
col1, col2 = st.columns([1, 5])
|
| 17 |
+
|
| 18 |
+
with col1:
|
| 19 |
+
st.markdown(f"<h1 style='text-align: center; color: #4caf50;'>{emoji}</h1>", unsafe_allow_html=True)
|
| 20 |
+
|
| 21 |
+
with col2:
|
| 22 |
+
st.subheader(title)
|
| 23 |
+
st.write(description)
|
| 24 |
+
st.link_button("Ouvrir " + title, url, help=None, type="secondary", disabled=False, use_container_width=True)
|
| 25 |
+
|
| 26 |
+
st.divider()
|
| 27 |
+
|
| 28 |
+
# Base64 encoding function for images
|
| 29 |
+
def get_image_as_base64(path):
|
| 30 |
+
with open(path, "rb") as image_file:
|
| 31 |
+
return base64.b64encode(image_file.read()).decode()
|
| 32 |
+
|
| 33 |
+
# Load image and get base64
|
| 34 |
+
image_path = "EDUCA.png"
|
| 35 |
+
image_base64 = get_image_as_base64(image_path)
|
| 36 |
+
|
| 37 |
+
# Display the image with rounded corners
|
| 38 |
+
st.markdown(
|
| 39 |
+
f'<img src="data:image/png;base64,{image_base64}" style="border-radius: 10px; width: 100%;">',
|
| 40 |
+
unsafe_allow_html=True
|
| 41 |
+
)
|
| 42 |
+
|
| 43 |
+
# Affichage d'un titre pour l'application et d'une barre de recherche
|
| 44 |
+
st.title("🏫 Ressources de EDUCA")
|
| 45 |
+
search_query = st.text_input("🔍 Recherche", "")
|
| 46 |
+
|
| 47 |
+
# Filtre les ressources basé sur la recherche
|
| 48 |
+
filtered_resources = [res for res in resources if search_query.lower() in res["Nom"].lower() or search_query.lower() in res["Description"].lower()]
|
| 49 |
+
|
| 50 |
+
# Créons les tabs
|
| 51 |
+
tab_all, tab_spaces, tab_models, tab_datasets = st.tabs(["✨ Tout", "🚀 Espaces", "📼 Modèles", "📁 Datasets"])
|
| 52 |
+
|
| 53 |
+
# Fonction pour afficher les ressources filtrées dans chaque onglet
|
| 54 |
+
def show_resources(filtered_resources, category):
|
| 55 |
+
displayed_resources = [res for res in filtered_resources if res["Categorie"] == category]
|
| 56 |
+
if displayed_resources:
|
| 57 |
+
for res in displayed_resources:
|
| 58 |
+
create_card(res["Emoji"], res["Nom"], res["Description"], res["Url"])
|
| 59 |
+
else:
|
| 60 |
+
st.error("🔴 Rien pour le moment.")
|
| 61 |
+
|
| 62 |
+
# Tab Tout
|
| 63 |
+
with tab_all:
|
| 64 |
+
st.header("Toutes les ressources")
|
| 65 |
+
if filtered_resources:
|
| 66 |
+
for res in filtered_resources:
|
| 67 |
+
create_card(res["Emoji"], res["Nom"], res["Description"], res["Url"])
|
| 68 |
+
else:
|
| 69 |
+
st.error("🔴 Aucune ressource ne correspond à votre recherche.")
|
| 70 |
+
|
| 71 |
+
# Tabs pour chaque catégorie avec les ressources filtrées
|
| 72 |
+
with tab_spaces:
|
| 73 |
+
st.header("Espaces")
|
| 74 |
+
show_resources(filtered_resources, "Space")
|
| 75 |
+
|
| 76 |
+
with tab_models:
|
| 77 |
+
st.header("Modèles")
|
| 78 |
+
show_resources(filtered_resources, "Model")
|
| 79 |
+
|
| 80 |
+
with tab_datasets:
|
| 81 |
+
st.header("Datasets")
|
| 82 |
+
show_resources(filtered_resources, "Dataset")
|