File size: 2,146 Bytes
ddd3e56
2e4a27d
 
 
ddd3e56
2e4a27d
ddd3e56
2e4a27d
ddd3e56
 
2e4a27d
ddd3e56
 
2e4a27d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ddd3e56
2e4a27d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ddd3e56
 
 
 
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import gradio as gr
import requests
import re
import yaml

def fetch_module(url: str) -> str:
    """
    Fetch the raw content of a file from a GitHub URL.

    Args:
        url (str): The URL of the GitHub file. Can be a standard GitHub URL or a raw URL.

    Returns:
        str: The raw text content of the file.

    Raises:
        requests.HTTPError: If the HTTP request fails.
    """
    if "github.com" in url and "raw.githubusercontent.com" not in url:
        url = url.replace("github.com", "raw.githubusercontent.com").replace("/blob/", "/")
    response = requests.get(url)
    response.raise_for_status()
    return response.text

def extract_nfcore_meta_io(url: str) -> dict:
    """
    Extract input and output metadata from a nf-core module YAML file.

    Args:
        url (str): The URL to the nf-core module's meta.yml file.

    Returns:
        dict: A dictionary with 'inputs' and 'outputs' keys, each containing lists of files or terms.

    Example:
        {
            "inputs": [...],
            "outputs": [...]
        }
    """
    content = fetch_module(url)
    meta = yaml.safe_load(content)
    inputs = meta.get("input", [])
    outputs = meta.get("output", [])
    return {"inputs": inputs, "outputs": outputs}

with gr.Blocks() as demo:
    gr.Markdown("# Multi-Tool App")
    with gr.Tab("nf-core Module Meta i/o Extractor"):
        gr.Interface(
            fn=extract_nfcore_meta_io,
            inputs=gr.Textbox(
                placeholder="Paste nf-core module URL...",
                label="nf-core module meta.yml URL",
                info="Paste the URL to the meta.yml file of a nf-core module. Example: https://github.com/nf-core/modules/blob/master/modules/nf-core/fastqc/meta.yml"
            ),
            outputs=gr.JSON(label="Meta inputs and outputs"),
            title="nf-core Module Meta i/o Extractor",
            description="Extracts input/output files from a nf-core module's meta.yml file. Provide the URL to the meta.yml file in a nf-core module repository."
        )

# Launch the interface and MCP server
if __name__ == "__main__":
    demo.launch(mcp_server=True)