Spaces:
Running
Running
File size: 4,350 Bytes
ac117b5 71382c0 fda141d 19dfa7a 0c8cec9 fda141d 71382c0 fda141d f98cc68 0c8cec9 fda141d 62efb75 0c8cec9 f98cc68 fda141d 19dfa7a fda141d 19dfa7a fda141d f98cc68 fda141d 0c8cec9 fda141d 0c8cec9 fda141d 62efb75 fda141d 62efb75 0c8cec9 19dfa7a fda141d 19dfa7a 7e647be 62efb75 83811e8 7e647be 19dfa7a 83811e8 fda141d 7e647be fda141d 19dfa7a 62efb75 83811e8 7e647be 62efb75 7e647be 83811e8 62efb75 83811e8 19dfa7a fda141d 71382c0 19dfa7a 71382c0 ac117b5 19dfa7a 0c8cec9 ac117b5 |
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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
import gradio as gr
from mammal_demo.demo_framework import (
ModelRegistry,
TaskRegistry,
)
from mammal_demo.dti_task import DtiTask
from mammal_demo.ppi_task import PpiTask
from mammal_demo.ps_task import PsTask
from mammal_demo.tcr_task import TcrTask
all_tasks = TaskRegistry()
all_models = ModelRegistry()
# first create the required tasks
# Note that the tasks need access to the models, as the model to use depends on the state of the widget
# we pass the all_models dict and update it when we actualy have the models.
ppi_task = all_tasks.register_task(PpiTask(model_dict=all_models))
tdi_task = all_tasks.register_task(DtiTask(model_dict=all_models))
ps_task = all_tasks.register_task(PsTask(model_dict=all_models))
tcr_task = all_tasks.register_task(TcrTask(model_dict=all_models))
# create the model holders. hold the model and the tokenizer, lazy download
# note that the list of relevent tasks needs to be stated.
all_models.register_model(
model_path="ibm/biomed.omics.bl.sm.ma-ted-458m.dti_bindingdb_pkd",
task_list=[tdi_task],
)
all_models.register_model(
model_path="ibm/biomed.omics.bl.sm.ma-ted-458m.tcr_epitope_bind",
task_list=[tcr_task],
)
all_models.register_model(
model_path="ibm/biomed.omics.bl.sm.ma-ted-458m.protein_solubility",
task_list=[ps_task],
)
all_models.register_model(
model_path="ibm/biomed.omics.bl.sm.ma-ted-458m",
task_list=[ppi_task],
)
all_models.register_model(
"https://huggingface.co/ibm/biomed.omics.bl.sm.ma-ted-458m.moleculenet_clintox_tox"
)
all_models.register_model(
"https://huggingface.co/ibm/biomed.omics.bl.sm.ma-ted-458m.moleculenet_clintox_fda"
)
all_models.register_model(
"https://huggingface.co/ibm/biomed.omics.bl.sm.ma-ted-458m.moleculenet_bbbp"
)
def create_application():
def task_change(value):
visibility = [gr.update(visible=(task == value)) for task in all_tasks.keys()]
choices = [
model_name
for model_name, model in all_models.items()
if value in model.tasks
]
if choices:
return (
gr.update(choices=choices, value=choices[0], visible=True),
*visibility,
)
else:
return (gr.update(visible=False, value=None), *visibility)
def model_change(value):
return gr.update(
value=f'[<span style="font-size:4em;">🤗</span>to model](https://huggingface.co/{value})',
visible=value is not None,
)
with gr.Blocks(theme="Zarkel/IBM_Carbon_Theme") as application:
task_dropdown = gr.Dropdown(
choices=["Select task"] + list(all_tasks.keys()),
label="Mammal Task",
)
task_dropdown.interactive = True
with gr.Row():
model_name_dropdown = gr.Dropdown(
choices=[
model_name
for model_name, model in all_models.items()
if task_dropdown.value in model.tasks
],
interactive=True,
label="Matching Mammal models",
visible=False,
scale=10,
)
goto_card_button = gr.Markdown(
"Link to model card",
visible=False,
)
def echo(value):
print(value)
return value
# goto_card_button.click(
# fn=None,
# inputs=model_name_dropdown,
# js=f"(model_name_dropdown) => {{ window.open('https://huggingface.co/{model_name_dropdown}', '_blank') }}",
# )
model_name_dropdown.change(
model_change, inputs=[model_name_dropdown], outputs=[goto_card_button]
)
task_dropdown.change(
task_change,
inputs=[task_dropdown],
outputs=[model_name_dropdown]
+ [
all_tasks[task].demo(model_name_widgit=model_name_dropdown)
for task in all_tasks
],
)
return application
full_demo = None
def main():
global full_demo
full_demo = create_application()
full_demo.launch(show_error=True, share=False)
# full_demo.launch(show_error=True, share=True)
if __name__ == "__main__":
main()
|