File size: 1,303 Bytes
f25eebc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a75df50
 
f25eebc
 
 
 
 
 
a75df50
f25eebc
 
 
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
from typing import Any, Dict, List, Optional

import gradio as gr
from core import MCPyLate
from huggingface_hub import snapshot_download

"""
MCPyLate Server
A Model Context Protocol server that provides search functionality using PyLate.
"""

snapshot_download(
    repo_id="lightonai/leetcode_reasonmoderncolbert",
    local_dir="indexes/",
    repo_type="dataset",
)
mcpylate = MCPyLate()


def pylate_search_leetcode(
    query: str, k: int = 10, index_name: Optional[str] = None
) -> List[Dict[str, Any]]:
    """
    Search the PyLate with multi-vector models in the leetcode collection containing code problems solutions and return top-k hits
    Args:
        query: Search query string
        k: Number of results to return (default: 10)
        index_name: Name of index to search (default: use default index)
    Returns:
        List of search results with docid, score, text snippet, and index name
    """
    return mcpylate.search(query, k)


with open("README.md", "r", encoding="utf-8") as f:
    readme_content = f.read()
demo = gr.Interface(
    fn=pylate_search_leetcode,
    inputs=["text"],
    outputs="text",
    title="LeetCode Search",
    description="Search in leetcode database index using PyLate",
    article=readme_content,
)

demo.launch(mcp_server=True, share=True)