gusdelact commited on
Commit
57e7291
·
verified ·
1 Parent(s): 09bc219

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. rag_books_mcp/app.py +23 -29
  2. rag_books_mcp/ingest.py +4 -5
rag_books_mcp/app.py CHANGED
@@ -34,21 +34,18 @@ def _build_search_tab() -> gr.Interface:
34
  placeholder="Consulta en lenguaje natural",
35
  ),
36
  gr.Radio(
37
- choices=["all", "both", "esl", "islp", "fes", "pdsh"],
38
  value="all",
39
  label="book",
40
- info=(
41
- "R4DS no se ofrece en este Space por su licencia CC BY-NC-ND. "
42
- "Disponible solo en la variante local con RAG_CHROMA_DIR."
43
- ),
44
  ),
45
  gr.Slider(minimum=1, maximum=10, step=1, value=5, label="top_k"),
46
  ],
47
  outputs=gr.Markdown(label="Resultados"),
48
  title="🔎 search_theory",
49
  description=(
50
- "Búsqueda semántica en ESL, ISLP, FES y PDSH. Devuelve los fragmentos "
51
- "más relevantes ordenados por similitud."
52
  ),
53
  api_name="search_theory",
54
  )
@@ -58,7 +55,7 @@ def _build_get_section_tab() -> gr.Interface:
58
  return gr.Interface(
59
  fn=get_section,
60
  inputs=[
61
- gr.Radio(choices=["esl", "islp", "fes", "pdsh"], value="islp", label="book"),
62
  gr.Textbox(
63
  label="chapter",
64
  value="8 Tree-Based Methods",
@@ -74,8 +71,8 @@ def _build_get_section_tab() -> gr.Interface:
74
  outputs=gr.Markdown(label="Sección"),
75
  title="📑 get_section",
76
  description=(
77
- "Recupera una sección específica de ESL, ISLP, FES o PDSH. Si no se "
78
- "encuentra por metadata, hace fallback a búsqueda semántica."
79
  ),
80
  api_name="get_section",
81
  )
@@ -88,7 +85,7 @@ def _build_cite_tab() -> gr.Interface:
88
  gr.Textbox(
89
  label="topic",
90
  value="ridge regression",
91
- placeholder="Tema a fundamentar (ej: 'bagging', 'feature selection')",
92
  ),
93
  gr.Radio(
94
  choices=["brief", "medium", "deep"],
@@ -99,9 +96,9 @@ def _build_cite_tab() -> gr.Interface:
99
  outputs=gr.Markdown(label="Fundamentación"),
100
  title="📚 cite_foundation",
101
  description=(
102
- "Fundamentación teórica que cita los libros publicados: "
103
- "ISLP (intuitivo), ESL (riguroso), FES (feature engineering) y "
104
- "PDSH (código Python)."
105
  ),
106
  api_name="cite_foundation",
107
  )
@@ -120,35 +117,32 @@ def _build_list_topics_tab() -> gr.Interface:
120
 
121
  def build_demo() -> gr.Blocks:
122
  """Construye la UI tabulada del MCP Server v2."""
123
- with gr.Blocks(title="rag-books-mcp v2 · ESL + ISLP + FES + PDSH") as demo:
124
  gr.Markdown(
125
  """
126
- # 📖 RAG Books MCP v2 — ESL + ISLP + FES + PDSH
127
 
128
- Servidor MCP que expone búsqueda semántica sobre cuatro libros de
129
- referencia de Statistical Learning y Data Science:
130
 
131
  - **ESL** — *The Elements of Statistical Learning* (Hastie, Tibshirani, Friedman)
132
  - **ISLP** — *An Introduction to Statistical Learning with Python* (James, Witten, Hastie, Tibshirani)
133
  - **FES** — *Feature Engineering and Selection* (Kuhn, Johnson)
134
  - **PDSH** — *Python Data Science Handbook* (VanderPlas)
 
135
 
136
- > ℹ️ **Sobre R4DS** *R for Data Science, 2nd Ed.* (Wickham et al.)
137
- > está indexado en la **variante local** del server pero **NO**
138
- > en este Space. La razón es su licencia CC BY-NC-ND 3.0 US
139
- > (NoDerivatives), incompatible con redistribución pública en
140
- > formato vectorial. Para usarlo, corre el server localmente con
141
- > `RAG_CHROMA_DIR` apuntando a tu propio `chroma_db/` con R4DS
142
- > indexado. Detalles en el [DATA_CARD del dataset](https://huggingface.co/datasets/gusdelact/rag-esl-islp-chromadb).
143
 
144
  **v2 vs v1:** la base ChromaDB se carga desde el dataset HF
145
- `gusdelact/rag-esl-islp-chromadb` en lugar de empaquetarla con el
146
- código. Permite versionar el índice independientemente y reusarlo
147
- desde otros clientes.
148
 
149
  **Endpoint MCP:** `/gradio_api/mcp/` (streamable HTTP).
150
  **Embeddings:** `sentence-transformers/all-MiniLM-L6-v2` (local, sin API key).
151
- **Vector store:** ChromaDB con 3005 chunks (1093 ESL + 884 ISLP + 465 FES + 563 PDSH).
152
 
153
  La primera tool call descarga el dataset (~95 MB). Las siguientes
154
  son cache hit.
 
34
  placeholder="Consulta en lenguaje natural",
35
  ),
36
  gr.Radio(
37
+ choices=["all", "both", "esl", "islp", "fes", "pdsh", "r4ds"],
38
  value="all",
39
  label="book",
40
+ info="R4DS está en R/tidyverse; los principios se traducen a pandas/seaborn.",
 
 
 
41
  ),
42
  gr.Slider(minimum=1, maximum=10, step=1, value=5, label="top_k"),
43
  ],
44
  outputs=gr.Markdown(label="Resultados"),
45
  title="🔎 search_theory",
46
  description=(
47
+ "Búsqueda semántica en ESL, ISLP, FES, PDSH y R4DS. Devuelve los "
48
+ "fragmentos más relevantes ordenados por similitud."
49
  ),
50
  api_name="search_theory",
51
  )
 
55
  return gr.Interface(
56
  fn=get_section,
57
  inputs=[
58
+ gr.Radio(choices=["esl", "islp", "fes", "pdsh", "r4ds"], value="islp", label="book"),
59
  gr.Textbox(
60
  label="chapter",
61
  value="8 Tree-Based Methods",
 
71
  outputs=gr.Markdown(label="Sección"),
72
  title="📑 get_section",
73
  description=(
74
+ "Recupera una sección específica de ESL, ISLP, FES, PDSH o R4DS. Si "
75
+ "no se encuentra por metadata, hace fallback a búsqueda semántica."
76
  ),
77
  api_name="get_section",
78
  )
 
85
  gr.Textbox(
86
  label="topic",
87
  value="ridge regression",
88
+ placeholder="Tema a fundamentar (ej: 'bagging', 'feature selection', 'EDA')",
89
  ),
90
  gr.Radio(
91
  choices=["brief", "medium", "deep"],
 
96
  outputs=gr.Markdown(label="Fundamentación"),
97
  title="📚 cite_foundation",
98
  description=(
99
+ "Fundamentación teórica que cita los 5 libros: ISLP (intuitivo), "
100
+ "ESL (riguroso), FES (feature engineering), PDSH (código Python) y "
101
+ "R4DS (workflow iterativo de EDA y data wrangling)."
102
  ),
103
  api_name="cite_foundation",
104
  )
 
117
 
118
  def build_demo() -> gr.Blocks:
119
  """Construye la UI tabulada del MCP Server v2."""
120
+ with gr.Blocks(title="rag-books-mcp v2 · ESL + ISLP + FES + PDSH + R4DS") as demo:
121
  gr.Markdown(
122
  """
123
+ # 📖 RAG Books MCP v2 — ESL + ISLP + FES + PDSH + R4DS
124
 
125
+ Servidor MCP que expone búsqueda semántica sobre cinco libros de
126
+ referencia de Statistical Learning, Data Science y Data Wrangling:
127
 
128
  - **ESL** — *The Elements of Statistical Learning* (Hastie, Tibshirani, Friedman)
129
  - **ISLP** — *An Introduction to Statistical Learning with Python* (James, Witten, Hastie, Tibshirani)
130
  - **FES** — *Feature Engineering and Selection* (Kuhn, Johnson)
131
  - **PDSH** — *Python Data Science Handbook* (VanderPlas)
132
+ - **R4DS** — *R for Data Science, 2nd Ed.* (Wickham, Çetinkaya-Rundel, Grolemund) — _ejemplos en R/tidyverse, principios universales para EDA y data wrangling_
133
 
134
+ > ℹ️ R4DS está bajo licencia CC BY-NC-ND 3.0 US y está incluido en
135
+ > este dataset bajo uso académico. Detalles, atribución y mecanismo
136
+ > de takedown en el [DATA_CARD del dataset](https://huggingface.co/datasets/gusdelact/rag-esl-islp-chromadb).
 
 
 
 
137
 
138
  **v2 vs v1:** la base ChromaDB se carga desde el dataset HF
139
+ `gusdelact/rag-esl-islp-chromadb` (tag `v2.2.0`) en lugar de
140
+ empaquetarla con el código. Permite versionar el índice
141
+ independientemente y reusarlo desde otros clientes.
142
 
143
  **Endpoint MCP:** `/gradio_api/mcp/` (streamable HTTP).
144
  **Embeddings:** `sentence-transformers/all-MiniLM-L6-v2` (local, sin API key).
145
+ **Vector store:** ChromaDB con 3689 chunks (1093 ESL + 884 ISLP + 465 FES + 563 PDSH + 684 R4DS).
146
 
147
  La primera tool call descarga el dataset (~95 MB). Las siguientes
148
  son cache hit.
rag_books_mcp/ingest.py CHANGED
@@ -52,11 +52,10 @@ BOOKS_CONFIG = {
52
  "principles transfer to pandas/Python"
53
  ),
54
  # ⚠️ R4DS está bajo licencia CC BY-NC-ND 3.0 US (NoDerivatives).
55
- # `local_only=True` indica que esta colección NO debe redistribuirse
56
- # como dataset HF público. `publish_chroma_dataset.py` la elimina del
57
- # snapshot antes de subir al Hub. Para uso local (RAG_CHROMA_DIR) el
58
- # comportamiento es transparente.
59
- "local_only": True,
60
  },
61
  }
62
 
 
52
  "principles transfer to pandas/Python"
53
  ),
54
  # ⚠️ R4DS está bajo licencia CC BY-NC-ND 3.0 US (NoDerivatives).
55
+ # Originalmente local_only=True para no redistribuir; se cambió a False
56
+ # para uso académico explícito. La decisión y el mecanismo de takedown
57
+ # están documentados en DATA_CARD.md.
58
+ "local_only": False,
 
59
  },
60
  }
61