File size: 1,040 Bytes
27e2770
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr

from get_index import get_engine

index_repo = "ronig/siamese_protein_index"
model_repo = "ronig/protein_search_engine"
engine = get_engine(index_repo, model_repo)


def search(seq, n_res):
    n_res = int(limit_n_results(n_res))
    search_results = engine.search_by_sequence(seq, n=n_res)
    outputs = {}
    for res in search_results:
        prot = res["protein_name"][0]
        chain = res["chain_id"][0]
        value = res["score"]
        key = f"Protein: {prot} | Chain: {chain}"
        outputs[key] = value
    return outputs


def limit_n_results(n):
    return max(min(n, 20), 1)


with gr.Blocks() as demo:
    with gr.Row():
        with gr.Column():
            seq_input = gr.Textbox("KFLIYQMECSTMIFGL", label="Input Sequence")
            n_results = gr.Number(5, label="N Results")
            search_button = gr.Button("Search")
        output = gr.Label(num_top_classes=20, label="Search Results")
        search_button.click(search, inputs=[seq_input, n_results], outputs=output)

demo.launch()