Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader
|
| 4 |
+
from llama_index.core.node_parser import SentenceSplitter
|
| 5 |
+
from llama_index.embeddings.huggingface import HuggingFaceEmbedding
|
| 6 |
+
from llama_index.core import Settings
|
| 7 |
+
|
| 8 |
+
# Configurar embeddings gratuitos y parser
|
| 9 |
+
Settings.node_parser = SentenceSplitter(chunk_size=512, chunk_overlap=50)
|
| 10 |
+
Settings.embed_model = HuggingFaceEmbedding(model_name="sentence-transformers/all-MiniLM-L6-v2")
|
| 11 |
+
|
| 12 |
+
# Cargar documentos y construir índice
|
| 13 |
+
documents = SimpleDirectoryReader(input_dir=".", recursive=True, required_exts=[".pdf"]).load_data()
|
| 14 |
+
index = VectorStoreIndex.from_documents(documents)
|
| 15 |
+
|
| 16 |
+
# Crear motor de consulta
|
| 17 |
+
query_engine = index.as_query_engine()
|
| 18 |
+
|
| 19 |
+
def responder(pregunta):
|
| 20 |
+
respuesta = query_engine.query(pregunta)
|
| 21 |
+
return str(respuesta)
|
| 22 |
+
|
| 23 |
+
iface = gr.Interface(fn=responder, inputs="text", outputs="text",
|
| 24 |
+
title="Asistente de Bioestadística",
|
| 25 |
+
description="Haz una pregunta sobre el curso. Responderé basándome en el sílabo y calendario oficial.")
|
| 26 |
+
iface.launch()
|