-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
61 lines (50 loc) · 1.76 KB
/
utils.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
import pandas as pd
import streamlit as st
from PIL import Image
import os
@st.cache_data(ttl=3600)
def load_data(path="data/Instructional_Design_Models_v3.xlsx"):
try:
data = pd.read_excel(path)
data.fillna("No available data", inplace=True)
return data
except Exception as e:
st.error(f"Failed to load data: {e}")
return pd.DataFrame() # Return an empty DataFrame on failure
from PIL import Image
@st.cache_data(ttl=3600)
def find_and_load_image(image_name, directory="data/images"):
extensions = ["png", "jpg", "gif", "JPG"]
for ext in extensions:
image_path = os.path.join(directory, f"{image_name}.{ext}")
if os.path.exists(image_path):
try:
# Open and return the image without closing the file stream
img = Image.open(image_path)
return img
except Exception as e:
st.error(f"Error loading image: {e}")
return None
st.error("Image not found.")
return None
def display_image(image):
"""Displays the PIL image directly in Streamlit."""
if image:
st.image(image, caption="Design (Scheme and source)")
else:
st.error("Failed to load and display the image.")
@st.cache_data(ttl=3600)
def add_logo():
st.markdown(
f"""
<style>
[data-testid="stSidebar"] {{
background-image: url(https://www.thevillageproject.eu/wp-content/uploads/2023/05/cropped-village-logo_web-300x128.png);
background-repeat: no-repeat;
padding-top: 80px;
background-position: 20px 20px;
}}
</style>
""",
unsafe_allow_html=True,
)