Update rag_hf.py
Browse files
rag_hf.py
CHANGED
@@ -35,6 +35,61 @@ EX = Namespace("http://example.org/lang/")
|
|
35 |
# === CUSTOM CSS ===
|
36 |
st.markdown("""
|
37 |
<style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
.tech-badge {
|
39 |
background-color: #ecfdf5;
|
40 |
color: #065f46;
|
@@ -142,22 +197,90 @@ def generate_response(matrix, id_map, G, rdf, user_question, k, embedder):
|
|
142 |
|
143 |
def main():
|
144 |
methods, embedder = load_all_components()
|
145 |
-
st.
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
151 |
start = datetime.datetime.now()
|
152 |
response, lang_ids, context, rdf_data = generate_response(*method, query, k, embedder)
|
153 |
duration = (datetime.datetime.now() - start).total_seconds()
|
154 |
-
st.markdown(
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
161 |
|
162 |
if __name__ == "__main__":
|
163 |
main()
|
|
|
35 |
# === CUSTOM CSS ===
|
36 |
st.markdown("""
|
37 |
<style>
|
38 |
+
.header {
|
39 |
+
color: #2c3e50;
|
40 |
+
border-bottom: 2px solid #4f46e5;
|
41 |
+
padding-bottom: 0.5rem;
|
42 |
+
margin-bottom: 1.5rem;
|
43 |
+
}
|
44 |
+
.feature-card {
|
45 |
+
background-color: #f8fafc;
|
46 |
+
border-radius: 8px;
|
47 |
+
padding: 1rem;
|
48 |
+
margin: 0.5rem 0;
|
49 |
+
border-left: 3px solid #4f46e5;
|
50 |
+
}
|
51 |
+
.response-card {
|
52 |
+
background-color: #fdfdfd;
|
53 |
+
color: #1f2937;
|
54 |
+
border-radius: 8px;
|
55 |
+
padding: 1.5rem;
|
56 |
+
box-shadow: 0 2px 6px rgba(0,0,0,0.08);
|
57 |
+
margin: 1rem 0;
|
58 |
+
font-size: 1rem;
|
59 |
+
line-height: 1.5;
|
60 |
+
}
|
61 |
+
.language-card {
|
62 |
+
background-color: #f9fafb;
|
63 |
+
border-radius: 8px;
|
64 |
+
padding: 1rem;
|
65 |
+
margin: 0.5rem 0;
|
66 |
+
border: 1px solid #e5e7eb;
|
67 |
+
}
|
68 |
+
.sidebar-section {
|
69 |
+
margin-bottom: 1.5rem;
|
70 |
+
}
|
71 |
+
.sidebar-title {
|
72 |
+
font-weight: 600;
|
73 |
+
color: #4f46e5;
|
74 |
+
}
|
75 |
+
.suggested-question {
|
76 |
+
padding: 0.5rem;
|
77 |
+
margin: 0.25rem 0;
|
78 |
+
border-radius: 4px;
|
79 |
+
cursor: pointer;
|
80 |
+
transition: all 0.2s;
|
81 |
+
}
|
82 |
+
.suggested-question:hover {
|
83 |
+
background-color: #f1f5f9;
|
84 |
+
}
|
85 |
+
.metric-badge {
|
86 |
+
display: inline-block;
|
87 |
+
background-color: #e8f4fc;
|
88 |
+
padding: 0.25rem 0.5rem;
|
89 |
+
border-radius: 4px;
|
90 |
+
font-size: 0.85rem;
|
91 |
+
margin-right: 0.5rem;
|
92 |
+
}
|
93 |
.tech-badge {
|
94 |
background-color: #ecfdf5;
|
95 |
color: #065f46;
|
|
|
197 |
|
198 |
def main():
|
199 |
methods, embedder = load_all_components()
|
200 |
+
st.markdown("""
|
201 |
+
<div class="header">
|
202 |
+
<h1>🌍 Atlas de Lenguas: Lenguas Indígenas Sudamericanas</h1>
|
203 |
+
</div>
|
204 |
+
""", unsafe_allow_html=True)
|
205 |
+
|
206 |
+
with st.sidebar:
|
207 |
+
st.markdown("### 📚 Información de Contacto")
|
208 |
+
st.markdown("""
|
209 |
+
- <span class="tech-badge">Correo: jxvera@gmail.com</span>
|
210 |
+
""", unsafe_allow_html=True)
|
211 |
+
|
212 |
+
st.markdown("---")
|
213 |
+
st.markdown("### 🚀 Inicio Rápido")
|
214 |
+
st.markdown("""
|
215 |
+
1. **Escribe una pregunta** en el cuadro de entrada
|
216 |
+
2. **Haz clic en 'Analizar'** para obtener la respuesta
|
217 |
+
3. **Explora los resultados** con los detalles expandibles
|
218 |
+
""")
|
219 |
+
|
220 |
+
st.markdown("---")
|
221 |
+
st.markdown("### 🔍 Preguntas de Ejemplo")
|
222 |
+
questions = [
|
223 |
+
"¿Qué idiomas están en peligro en Brasil?",
|
224 |
+
"¿Qué idiomas se hablan en Perú?",
|
225 |
+
"¿Cuáles idiomas están relacionados con el Quechua?",
|
226 |
+
"¿Dónde se habla el Mapudungun?"
|
227 |
+
]
|
228 |
+
for q in questions:
|
229 |
+
if st.button(q, key=f"suggested_{q}", use_container_width=True):
|
230 |
+
st.session_state.query = q
|
231 |
+
|
232 |
+
st.markdown("---")
|
233 |
+
st.markdown("### 📊 Parámetros de Análisis")
|
234 |
+
k = st.slider("Número de idiomas a analizar", 1, 10, 3)
|
235 |
+
|
236 |
+
st.markdown("---")
|
237 |
+
st.markdown("### 🔧 Opciones Avanzadas")
|
238 |
+
show_ctx = st.checkbox("Mostrar información de contexto", False)
|
239 |
+
show_rdf = st.checkbox("Mostrar hechos estructurados", False)
|
240 |
+
|
241 |
+
st.markdown("### 📝 Haz una pregunta sobre lenguas indígenas")
|
242 |
+
query = st.text_input(
|
243 |
+
"Ingresa tu pregunta:",
|
244 |
+
value=st.session_state.get("query", ""),
|
245 |
+
label_visibility="collapsed",
|
246 |
+
placeholder="Ej. ¿Qué lenguas se hablan en Perú?"
|
247 |
+
)
|
248 |
+
|
249 |
+
if st.button("Analizar", type="primary", use_container_width=True):
|
250 |
+
if not query:
|
251 |
+
st.warning("Por favor, ingresa una pregunta")
|
252 |
+
return
|
253 |
+
label = "LinkGraph"
|
254 |
+
method = methods[label]
|
255 |
start = datetime.datetime.now()
|
256 |
response, lang_ids, context, rdf_data = generate_response(*method, query, k, embedder)
|
257 |
duration = (datetime.datetime.now() - start).total_seconds()
|
258 |
+
st.markdown(f"""
|
259 |
+
<div class="response-card">
|
260 |
+
{response}
|
261 |
+
<div style="margin-top: 1rem;">
|
262 |
+
<span class="metric-badge">⏱️ {duration:.2f}s</span>
|
263 |
+
<span class="metric-badge">🌐 {len(lang_ids)} idiomas</span>
|
264 |
+
</div>
|
265 |
+
</div>
|
266 |
+
""", unsafe_allow_html=True)
|
267 |
+
|
268 |
+
if show_ctx:
|
269 |
+
with st.expander(f"📖 Contexto de {len(lang_ids)} idiomas"):
|
270 |
+
for lang_id, ctx in zip(lang_ids, context):
|
271 |
+
st.markdown(f"<div class='language-card'>{ctx}</div>", unsafe_allow_html=True)
|
272 |
+
|
273 |
+
if show_rdf:
|
274 |
+
with st.expander("🔗 Hechos estructurados (RDF)"):
|
275 |
+
st.code("\n".join(rdf_data))
|
276 |
+
|
277 |
+
st.markdown("---")
|
278 |
+
st.markdown("""
|
279 |
+
<div style="font-size: 0.8rem; color: #64748b; text-align: center;">
|
280 |
+
<b>📌 Nota:</b> Esta herramienta está diseñada para investigadores, lingüistas y preservacionistas culturales.
|
281 |
+
Para mejores resultados, usa preguntas específicas sobre idiomas, familias o regiones.
|
282 |
+
</div>
|
283 |
+
""", unsafe_allow_html=True)
|
284 |
|
285 |
if __name__ == "__main__":
|
286 |
main()
|