Spaces:
Sleeping
Sleeping
Upload app.py with huggingface_hub
Browse files
app.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import json
|
| 3 |
+
|
| 4 |
+
# Placeholder para dados de busca
|
| 5 |
+
# Futuramente será integrado com embeddings e vector DB
|
| 6 |
+
|
| 7 |
+
SAMPLE_DOCS = [
|
| 8 |
+
{"title": "SEO Multilíngue", "content": "Estratégias de SEO para múltiplos idiomas..."},
|
| 9 |
+
{"title": "Marketing Digital", "content": "Serviços de marketing digital da MSC..."},
|
| 10 |
+
{"title": "Agentes de IA", "content": "Criação de agentes inteligentes para automação..."},
|
| 11 |
+
]
|
| 12 |
+
|
| 13 |
+
def search(query: str, top_k: int = 5):
|
| 14 |
+
"""Realiza busca semântica nos documentos."""
|
| 15 |
+
# Busca simples por enquanto
|
| 16 |
+
# Futuramente usará embeddings
|
| 17 |
+
|
| 18 |
+
results = []
|
| 19 |
+
query_lower = query.lower()
|
| 20 |
+
|
| 21 |
+
for doc in SAMPLE_DOCS:
|
| 22 |
+
if query_lower in doc["title"].lower() or query_lower in doc["content"].lower():
|
| 23 |
+
results.append(doc)
|
| 24 |
+
|
| 25 |
+
if not results:
|
| 26 |
+
results = SAMPLE_DOCS[:top_k]
|
| 27 |
+
|
| 28 |
+
return json.dumps(results, indent=2, ensure_ascii=False)
|
| 29 |
+
|
| 30 |
+
# Interface Gradio
|
| 31 |
+
with gr.Blocks(title="MSC Search") as demo:
|
| 32 |
+
gr.Markdown("# 🔍 MSC Marketing - Busca Semântica")
|
| 33 |
+
gr.Markdown("Busque na documentação da MSC Marketing")
|
| 34 |
+
|
| 35 |
+
with gr.Row():
|
| 36 |
+
query_input = gr.Textbox(label="Sua busca", placeholder="Digite sua busca...")
|
| 37 |
+
top_k_input = gr.Slider(1, 10, value=5, step=1, label="Número de resultados")
|
| 38 |
+
|
| 39 |
+
search_btn = gr.Button("Buscar", variant="primary")
|
| 40 |
+
results_output = gr.JSON(label="Resultados")
|
| 41 |
+
|
| 42 |
+
search_btn.click(search, inputs=[query_input, top_k_input], outputs=results_output)
|
| 43 |
+
|
| 44 |
+
gr.Markdown("""
|
| 45 |
+
---
|
| 46 |
+
**Nota:** Este Space está em fase de configuração inicial.
|
| 47 |
+
Em breve teremos busca semântica completa com embeddings.
|
| 48 |
+
""")
|
| 49 |
+
|
| 50 |
+
if __name__ == "__main__":
|
| 51 |
+
demo.launch()
|