-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
157 lines (129 loc) · 5.53 KB
/
main.py
File metadata and controls
157 lines (129 loc) · 5.53 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import streamlit as st
import pandas as pd
import lesihmania_activity_predictions
import base64
import os
# --- VERY IMPORTANT DEBUGGING LINES ---
font_filename = "VITOR.otf" # Let's stick to the .otf as per USAL instructions
current_dir = os.getcwd()
font_path = os.path.join(current_dir, font_filename)
if not os.path.exists(font_path):
st.error(f"ERROR: The font file `{font_filename}` was NOT found at the expected path: `{font_path}`.")
st.error("Please ensure the font file is in the same directory as your Streamlit script.")
st.stop() # Stop execution if file not found, no point in proceeding
def load_font_base64(path):
try:
with open(path, "rb") as f:
encoded_font = base64.b64encode(f.read()).decode('utf-8')
return encoded_font
except Exception as e:
st.error(f"Error reading or encoding font file '{path}': {e}")
st.stop() # Stop if there's an error during file reading/encoding
font_base64 = load_font_base64(font_path)
if not font_base64:
st.error("ERROR: Base64 encoding resulted in an empty string. This should not happen if the file was read.")
st.stop() # Stop if base64 is empty
st.set_page_config(
page_title="Departamento de Ciencias Farmacéuticas - USAL",
page_icon="🧪",
layout="wide",
initial_sidebar_state="collapsed"
)
st.markdown(f"""
<style>
/* Font-face declaration */
@font-face {{
font-family: 'USAL';
src: url(data:font/otf;base64,{font_base64}) format('opentype');
/* Consider adding these if the font supports them and you want to be explicit */
font-weight: normal;
font-style: normal;
/* display: swap; /* Helps with font loading strategy */
}}
/* Apply font to relevant elements */
html, body, [class*="css"], .stApp {{ /* .stApp targets the main Streamlit container */
font-family: 'USAL', serif !important; /* !important to override other rules */
background-color: #ffffff;
color: #2a2a2a;
}}
h1{{
font-family: 'USAL', serif !important; /* Ensure headers also use it */
color: #d22020; /* USAL red */
}}
h1, [class^="stMarkdown"] h1{{
font-family: 'USAL', serif !important; /* Ensure headers also use it */
color: #d22020; /* USAL red */
}}
.stTextArea > div > div > textarea {{
font-family: 'monospace'; /* Keep text area as monospace for SMILES */
}}
/* Aplica el color a las etiquetas de los text_area */
.stTextArea label,
.stTextArea label span,
.stTextArea label div {{
color: #2a2a2a !important;
}}
.block-container {{
padding-top: 2rem;
}}
.dataframe {{
width: 100%;
}}
.dataframe td:nth-child(1) {{
width: 90%;
}}
.dataframe td:nth-child(2) {{
width: 10%;
}}
/* Target Streamlit buttons correctly */
.stButton > button {{
background-color: #d22020 !important;
color: white !important;
border: none !important;
font-family: 'USAL', serif !important;
font-size: 1rem !important;
padding: 0.75rem 1.25rem !important;
line-height: 1.2 !important;
border-radius: 0.3rem !important;
transition: background-color 0.2s ease-in-out;
}}
/* Hover state */
.stButton > button:hover {{
background-color: #800000 !important;
color: white !important;
}}
/* Focus state */
.stButton > button:focus {{
outline: 2px solid #990000 !important;
outline-offset: 2px !important;
}}
</style>
""", unsafe_allow_html=True)
st.markdown("<h1>Departamento de Ciencias Farmacéuticas - USAL</h1>", unsafe_allow_html=True)
st.markdown("<h6>Herramienta para predecir actividad contra Leishmania* con IC50 < 10 µM.</h6>", unsafe_allow_html=True)
smiles_input = st.text_area(
label="Ingrese uno o más SMILES (uno por línea):",
height=200,
placeholder="Ejemplo:\nCC(=O)Oc1ccccc1C(=O)O\nCCN(CC)CC\nC1=CC=CN=C1"
)
if st.button("Predecir actividad"):
if smiles_input.strip():
smiles_list = [s.strip() for s in smiles_input.strip().splitlines() if s.strip()]
probabilities_df = lesihmania_activity_predictions.calculate_leishmania_activity(smiles_list)
st.dataframe(probabilities_df, use_container_width=True)
else:
st.warning("Por favor, ingrese al menos un SMILES.")
st.markdown("<h4>Recuerde que:</h4>", unsafe_allow_html=True)
st.markdown("<h6>Una probabilidad mayor a 0,5 indica actividad potencial.</h6>", unsafe_allow_html=True)
st.markdown("<h6>Mayor probabilidad no indica mayor actividad.</h6>", unsafe_allow_html=True)
st.markdown("""
<span style="font-size: 0.9rem; color: #555; margin-top: 3rem; font-style: italic;">
* L. major, L. donovani, L. infantum, L. mexicana, L. braziliensis
</span>
""", unsafe_allow_html=True)
st.markdown("""
<p style="font-size: 0.9rem; color: #555; margin-top: 3rem;">
© 2025 - Aplicación desarrollada por estudiantes de Maestría del Solftware con énfasis en Inteligencia Artificial de Universidad CENFOTEC para el Departamento de Ciencias Farmacéuticas de la Universidad de Salamanca.<br>
Para consultas técnicas, puede escribir a <a href="mailto:avillalobosh@ucenfotec.ac.cr">avillalobosh@ucenfotec.ac.cr</a>.
</p>
""", unsafe_allow_html=True)