Spaces:
Sleeping
Sleeping
File size: 47,891 Bytes
3fdcc70 |
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 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 |
import sys
import os
sys.path.append(os.getcwd())
from cllm.services.image_editing.api import (
inpainting_ldm,
inpainting_ldm_general,
partial_image_editing,
instruct_pix2pix,
image_cropping,
image_matting,
draw_bbox_on_image,
)
from cllm.services.image_generation.api import (
text2image,
image2image,
cannytext2image,
linetext2image,
hedtext2image,
scribbletext2image,
posetext2image,
segtext2image,
depthtext2image,
normaltext2image,
)
from cllm.services.image_processing.api import (
image2canny,
image2line,
image2hed,
image2scribble,
image2pose,
image2depth,
image2normal,
)
from cllm.services.image_perception.api import (
object_detection,
image_classification,
ocr,
segment_objects,
visual_grounding,
image_captioning,
segment_all,
seg_by_mask,
seg_by_points,
)
from cllm.services.video.api import (
video_classification,
video_captioning,
image_audio_to_video,
video_to_webpage,
dub_video,
image_to_video,
text_to_video,
)
from cllm.services.audio.api import (
text_to_music,
text_to_speech,
audio_classification,
)
# from cllm.services.sam.api import (
# segment_by_mask,
# segment_by_points,
# set_image,
# segment_all,
# )
from cllm.services.general.api import (
select,
count,
remote_logging,
)
from cllm.services.nlp.api import (
text_to_text_generation,
title_generation,
text_to_tags,
question_answering_with_context,
openai_chat_model,
summarization,
extract_location,
sentiment_analysis,
get_weather,
summarize_weather_condition,
get_time,
)
from cllm.services.vqa.api import image_qa
from cllm.agents.base import Tool, DataType
QUESTION_ANSWERING_TOOLS = [
Tool(
name="image_question_answering",
description="answers a question about an image",
domain=Tool.Domain.VISUAL_QUESTION_ANSWERING,
args=[
Tool.Argument(
name="image",
type=DataType.IMAGE,
description="the image containing the information",
),
Tool.Argument(
name="text",
type=DataType.TEXT,
description="the question about the image",
),
],
returns=[
Tool.Argument(
name="response",
type=DataType.TEXT,
description="output response",
)
],
model=image_qa,
),
Tool(
name="get_weather",
description="Query the weather conditions by given location. For example: what is the weather in Beijing? how cold is in New York? etc.",
domain=Tool.Domain.QUESTION_ANSWERING,
args=[
Tool.Argument(
name="location",
type=DataType.LOCATION,
description="the location where the weather is to be queried",
),
],
returns=[
Tool.Argument(
name="result",
# type=DataType.WEATHER,
type=DataType.WEATHER,
description="weather information",
)
],
model=get_weather,
),
Tool(
name="get_time",
description="get current date",
domain=Tool.Domain.QUESTION_ANSWERING,
args=[
# Tool.Argument(
# name="location",
# type=DataType.LOCATION,
# description="location where the time is to be queried",
# ),
Tool.Argument(
name="text",
type=DataType.TEXT,
description="input text",
),
],
returns=[
Tool.Argument(
name="response",
type=DataType.TIME,
description="output time",
)
],
model=get_time,
),
# Tool(
# name="calculator",
# description="It can solve mathematics problems and support various mathematical expressions: from basic arithmetic to more complex expressions.",
# domain=Tool.Domain.QUESTION_ANSWERING,
# args=[
# Tool.Argument(
# name="text",
# type=DataType.TEXT,
# description="input instructions",
# ),
# ],
# returns=[
# Tool.Argument(
# name="result",
# type=DataType.TEXT,
# description="result about weather",
# )
# ],
# model=None,
# ),
]
IMAGE_CAPTIONING_TOOLS = [
Tool(
name="image_captioning",
description='Generate a caption or description for the image. It can generate a detailed description that can be used for image perception and image generation. For example: a) you can use this tool when you want to know what is it in the image"; and b) when you want to generate a new image similar or resemble to input.png, you can use `image_captioning` to obtain the description about image input.png.',
domain=Tool.Domain.IMAGE_PERCEPTION,
args=[
Tool.Argument(
name="image",
type=DataType.IMAGE,
description="the image to be captioned",
),
],
returns=[
Tool.Argument(
name="text",
type=DataType.TEXT,
description="the description for the input image",
)
],
model=image_captioning,
),
]
IMAGE_EDITING_TOOLS = [
Tool(
name="partial_image_editing",
description="Given the mask denoting the region to edit, Edit the given image at local region. Useful when you want to replace an object via a mask image. "
"like: replace the masked object with a dog. ",
domain=Tool.Domain.IMAGE_EDITING,
args=[
Tool.Argument(
name="image",
type=DataType.IMAGE,
description="the image to be edited",
),
Tool.Argument(
name="mask",
type=DataType.MASK,
description="the mask image representing the editing position",
),
Tool.Argument(
name="prompt",
type=DataType.TEXT,
description="the prompt specified the edition",
),
],
returns=[
Tool.Argument(
name="image",
type=DataType.IMAGE,
description="the edited image",
)
],
model=partial_image_editing,
),
Tool(
name="text_image_editing",
description="Edit the given image based on the text prompt.",
domain=Tool.Domain.IMAGE_EDITING,
args=[
Tool.Argument(
name="image",
type=DataType.IMAGE,
description="the image to be edited",
),
Tool.Argument(
name="text",
type=DataType.TEXT,
description="the prompt specified the edition",
),
],
returns=[
Tool.Argument(
name="image",
type=DataType.IMAGE,
description="the edited image",
)
],
model=instruct_pix2pix,
),
Tool(
name="image_inpainting",
description="inpaint the region of the image based on the given mask. For example: remove the dog in the image, erase the spoon in given image, etc.",
domain=Tool.Domain.IMAGE_EDITING,
usages=["remove some objects"],
args=[
Tool.Argument(
name="image",
type=DataType.IMAGE,
description="the image to be inpainted",
),
Tool.Argument(
name="mask",
type=DataType.MASK,
description="the segmentation mask for the inpainting region",
),
],
returns=[
Tool.Argument(
name="image",
type=DataType.IMAGE,
description="the processed image",
)
],
model=inpainting_ldm_general,
),
Tool(
name="highlight_object_on_image",
description="This tool is usually used after `object_detection` `visual_grounding` and `select_bbox`. Useful when you want to: 1) highlight the region of interest on the image; 2) know where the object is. For example: highlight the elephant from image, locate the dog in the image, find the spoon in given image, detect if the object is present in the image, etc.",
domain=Tool.Domain.IMAGE_EDITING,
usages=["highlight the region of interest on the image"],
args=[
Tool.Argument(
name="image",
type=DataType.IMAGE,
description="the image to be processed",
),
Tool.Argument(
name="bbox",
type=DataType.BBOX,
description="the bounding boxes that need to be drawn on the image",
),
],
returns=[
Tool.Argument(
name="result",
type=DataType.IMAGE,
description="the new image on which the tool highlight the the region of interest by bounding boxes",
)
],
model=draw_bbox_on_image,
),
Tool(
name="image_cropping",
description="Crop the image based on the given bounding box. Useful when you want to crop the dog in the image, crop the spoon in given image, etc.",
domain=Tool.Domain.IMAGE_EDITING,
args=[
Tool.Argument(
name="image",
type=DataType.IMAGE,
description="the image to be processed",
),
Tool.Argument(
name="object",
type=DataType.BBOX,
description="the detected object",
),
],
returns=[
Tool.Argument(
name="image",
type=DataType.IMAGE,
description="the cropped image",
)
],
model=image_cropping,
),
# Tool(
# name="mask_image",
# description="Mask the background from the image based on the given mask. For example: mask anything except the dog in the image, extract the spoon from given image without any inpainting, etc.",
# domain=Tool.Domain.IMAGE_EDITING,
# args=[
# Tool.Argument(
# name="image",
# type=DataType.IMAGE,
# description="the image to be processed",
# ),
# Tool.Argument(
# name="mask",
# type=DataType.MASK,
# description="the mask of the matted region",
# ),
# ],
# returns=[
# Tool.Argument(
# name="image",
# type=DataType.IMAGE,
# description="the matted image",
# )
# ],
# model=image_matting,
# ),
]
IMAGE_GENERATION_TOOLS = [
Tool(
name="text_to_image",
description="generate an image based on the given description.",
domain=Tool.Domain.IMAGE_GENERATION,
args=[
Tool.Argument(
name="text",
type=DataType.TEXT,
description="the text describing the image",
),
],
returns=[
Tool.Argument(
name="image",
type=DataType.IMAGE,
description="the generated image",
)
],
model=text2image,
),
Tool(
name="image_to_image",
description="generate an new image based on the given image.",
domain=Tool.Domain.IMAGE_GENERATION,
args=[
Tool.Argument(
name="image",
type=DataType.IMAGE,
description="the given image",
),
],
returns=[
Tool.Argument(
name="image",
type=DataType.IMAGE,
description="the generated image",
)
],
model=image2image,
),
Tool(
name="line_text_to_image",
description="generate an image based on the given description and line map.",
domain=Tool.Domain.IMAGE_GENERATION,
args=[
Tool.Argument(
name="text",
type=DataType.TEXT,
description="the text describing the image",
),
Tool.Argument(
name="line",
type=DataType.LINE,
description="the line map outlining the line of the image",
),
],
returns=[
Tool.Argument(
name="image",
type=DataType.IMAGE,
description="the generated image",
)
],
model=linetext2image,
),
Tool(
name="hed_text_to_image",
description="generate an image based on the given description and HED map (holistically-nested edge detection).",
domain=Tool.Domain.IMAGE_GENERATION,
args=[
Tool.Argument(
name="text",
type=DataType.TEXT,
description="the text describing the image",
),
Tool.Argument(
name="hed",
type=DataType.HED,
description="the HED map outlining the edge of the image",
),
],
returns=[
Tool.Argument(
name="image",
type=DataType.IMAGE,
description="the generated image",
)
],
model=hedtext2image,
),
Tool(
name="scribble_text_to_image",
description="generate an image based on the given description and the scribble.",
domain=Tool.Domain.IMAGE_GENERATION,
args=[
Tool.Argument(
name="text",
type=DataType.TEXT,
description="the text describing the image",
),
Tool.Argument(
name="scribble",
type=DataType.SCRIBBLE,
description="the scribble outlining the image",
),
],
returns=[
Tool.Argument(
name="image",
type=DataType.IMAGE,
description="the generated image",
)
],
model=scribbletext2image,
),
Tool(
name="pose_text_to_image",
description="generate an image based on the given description and the pose.",
domain=Tool.Domain.IMAGE_GENERATION,
args=[
Tool.Argument(
name="text",
type=DataType.TEXT,
description="the text describing the image",
),
Tool.Argument(
name="pose",
type=DataType.POSE,
description="the pose of the human in the image",
),
],
returns=[
Tool.Argument(
name="image",
type=DataType.IMAGE,
description="the generated image",
)
],
model=posetext2image,
),
Tool(
name="segmentation_text_to_image",
description="generate an image based on the given description and segmentation mask.",
domain=Tool.Domain.IMAGE_GENERATION,
args=[
Tool.Argument(
name="text",
type=DataType.TEXT,
description="the text describing the image",
),
Tool.Argument(
name="segmentation",
type=DataType.SEGMENTATION,
description="the segmentation mask describing the structure of the image",
),
],
returns=[
Tool.Argument(
name="image",
type=DataType.IMAGE,
description="the generated image",
)
],
model=segtext2image,
),
Tool(
name="edge_text_to_image",
description="generate an image based on the given description and edge map.",
domain=Tool.Domain.IMAGE_GENERATION,
args=[
Tool.Argument(
name="text",
type=DataType.TEXT,
description="the text describing the image",
),
Tool.Argument(
name="edge",
type=DataType.EDGE,
description="the edge map describing the structure of the image",
),
],
returns=[
Tool.Argument(
name="image",
type=DataType.IMAGE,
description="the generated image",
)
],
model=cannytext2image,
),
Tool(
name="depth_text_to_image",
description="generate an image based on the given description and depth map.",
domain=Tool.Domain.IMAGE_GENERATION,
args=[
Tool.Argument(
name="text",
type=DataType.TEXT,
description="the text describing the image",
),
Tool.Argument(
name="depth",
type=DataType.DEPTH,
description="the depth map describing the structure of the image",
),
],
returns=[
Tool.Argument(
name="image",
type=DataType.IMAGE,
description="the generated image",
)
],
model=depthtext2image,
),
Tool(
name="normal_text_to_image",
description="generate an image based on the given description and normal map.",
domain=Tool.Domain.IMAGE_GENERATION,
args=[
Tool.Argument(
name="text",
type=DataType.TEXT,
description="the text describing the image",
),
Tool.Argument(
name="normal",
type=DataType.NORMAL,
description="the normal map describing the structure of the image",
),
],
returns=[
Tool.Argument(
name="image",
type=DataType.IMAGE,
description="the generated image",
)
],
model=normaltext2image,
),
]
IMAGE_TRANSFORM_TOOLS = [
Tool(
name="image_to_edge",
description="get the edge map of the image.",
domain=Tool.Domain.IMAGE_PROCESSING,
args=[
Tool.Argument(
name="image",
type=DataType.IMAGE,
description="the image to be processed",
),
],
returns=[
Tool.Argument(
name="edge",
type=DataType.EDGE,
description="the edge map of the image",
)
],
model=image2canny,
),
Tool(
name="image_to_line",
description="get the line map of the image.",
domain=Tool.Domain.IMAGE_PROCESSING,
args=[
Tool.Argument(
name="image",
type=DataType.IMAGE,
description="the image to be processed",
),
],
returns=[
Tool.Argument(
name="line",
type=DataType.LINE,
description="the line map of the image",
)
],
model=image2line,
),
Tool(
name="image_to_hed",
description="get the HED map of the image.",
domain=Tool.Domain.IMAGE_PROCESSING,
args=[
Tool.Argument(
name="image",
type=DataType.IMAGE,
description="the image to be processed",
),
],
returns=[
Tool.Argument(
name="hed",
type=DataType.HED,
description="the hed map of the image",
)
],
model=image2hed,
),
Tool(
name="image_to_scribble",
description="get the scribble of the image.",
domain=Tool.Domain.IMAGE_PROCESSING,
args=[
Tool.Argument(
name="image",
type=DataType.IMAGE,
description="the image to be processed",
),
],
returns=[
Tool.Argument(
name="scribble",
type=DataType.SCRIBBLE,
description="the scribble of the image",
)
],
model=image2scribble,
),
Tool(
name="image_to_pose",
description="Get the pose of the image. It is usually used in image generation conditioned on pose map from input image.",
domain=Tool.Domain.IMAGE_PROCESSING,
args=[
Tool.Argument(
name="image",
type=DataType.IMAGE,
description="the image to be processed",
),
],
returns=[
Tool.Argument(
name="pose",
type=DataType.POSE,
description="the pose of the image",
)
],
model=image2pose,
),
Tool(
name="image_to_depth",
description="get the depth map of the image.",
domain=Tool.Domain.IMAGE_PROCESSING,
args=[
Tool.Argument(
name="image",
type=DataType.IMAGE,
description="the image to be processed",
),
],
returns=[
Tool.Argument(
name="depth",
type=DataType.DEPTH,
description="the depth map",
)
],
model=image2depth,
),
Tool(
name="image_to_normal",
description="get the normal map of the image.",
domain=Tool.Domain.IMAGE_PROCESSING,
args=[
Tool.Argument(
name="image",
type=DataType.IMAGE,
description="the image to be processed",
),
],
returns=[
Tool.Argument(
name="normal",
type=DataType.NORMAL,
description="the normal map",
)
],
model=image2normal,
),
]
IMAGE_PERCEPTION_TOOLS = [
Tool(
name="object_detection",
description="detect all the objects in the image.",
domain=Tool.Domain.IMAGE_PERCEPTION,
args=[
Tool.Argument(
name="image",
type=DataType.IMAGE,
description="the image that contains the objects",
),
],
returns=[
Tool.Argument(
name="object",
type=DataType.BBOX,
description="the detected objects in json format. "
"example output: [\{'score': 0.9994931221008301, 'label': 'dog', 'box': \{'xmin': 466, 'ymin': 301, 'xmax': 1045, 'ymax': 583\}\}]",
)
],
model=object_detection,
),
Tool(
name="image_classification",
description="classify the objects in the image.",
domain=Tool.Domain.IMAGE_PERCEPTION,
usages=["ask about the class of the image"],
args=[
Tool.Argument(
name="image",
type=DataType.IMAGE,
description="the image that contains the objects",
),
],
returns=[
Tool.Argument(
name="category",
type=DataType.CATEGORY,
description="the categories in json format. "
"example output: [\{'score': 0.9, 'label': 'dog'\}]",
)
],
model=image_classification,
),
Tool(
name="video_classification",
description="Classify the video and detect the actions in the video.",
domain=Tool.Domain.VIDEO_PERCEPTION,
usages=["ask about the class of the video"],
args=[
Tool.Argument(
name="video",
type=DataType.VIDEO,
description="the given video",
),
],
returns=[
Tool.Argument(
name="category",
type=DataType.CATEGORY,
description="the categories in json format. "
"example output: [\{'score': 0.9, 'label': 'Playing basketball'\}]",
)
],
model=video_classification,
),
Tool(
name="image_instance_segmentation",
description="segment the common objects in the given image.",
domain=Tool.Domain.IMAGE_PERCEPTION,
args=[
Tool.Argument(
name="image",
type=DataType.IMAGE,
description="the image that need to be segmented",
),
],
returns=[
Tool.Argument(
name="mask", type=DataType.MASK, description="the output mask"
)
],
model=segment_objects,
),
Tool(
name="image_segmentation_by_mask",
description="segment the given image with the prompt mask.",
domain=Tool.Domain.IMAGE_PERCEPTION,
args=[
Tool.Argument(
name="image",
type=DataType.IMAGE,
description="the image that need to be segmented",
),
Tool.Argument(
name="prompt_mask",
type=DataType.MASK,
description="the prompt mask that guides the segmentation",
),
],
returns=[
Tool.Argument(
name="mask", type=DataType.MASK, description="the output mask"
)
],
model=seg_by_mask,
),
Tool(
name="image_segmentation_by_points",
description="segment the given image with the prompt points.",
domain=Tool.Domain.IMAGE_PERCEPTION,
args=[
Tool.Argument(
name="image",
type=DataType.IMAGE,
description="the image that need to be segmented",
),
Tool.Argument(
name="prompt_points",
type=DataType.POINT,
description="the prompt points that guides the segmentation",
),
],
returns=[
Tool.Argument(
name="mask", type=DataType.MASK, description="the output mask"
)
],
model=seg_by_points,
),
Tool(
name="segment_anything",
description="Segment the given image without other inputs. This tool return the segmentation map for input image. The segmentation can be used to generate a new image.",
domain=Tool.Domain.IMAGE_PERCEPTION,
args=[
Tool.Argument(
name="image",
type=DataType.IMAGE,
description="the image that need to be segmented",
),
],
returns=[
Tool.Argument(
name="segmentation",
type=DataType.SEGMENTATION,
description="the output segmentation",
)
],
model=segment_all,
),
Tool(
name="visual_grounding",
description="Visual Grounding (VG) aims to locate the most relevant object or region in an image, based on a natural language query. The query can be a phrase, a sentence or even a multi-round dialogue.",
domain=Tool.Domain.IMAGE_PERCEPTION,
args=[
Tool.Argument(
name="image",
type=DataType.IMAGE,
description="the image that need to be processed",
),
Tool.Argument(
name="query",
type=DataType.TEXT,
description="a query that can be a phrase, a sentence",
),
],
returns=[
Tool.Argument(
name="bbox",
type=DataType.BBOX,
description="the detected bounding boxes for ",
)
],
model=visual_grounding,
),
Tool(
name="optical_character_recognition",
description="Optical Character Recognition (OCR) is the process that converts an image of text into a machine-readable text format.",
domain=Tool.Domain.IMAGE_PERCEPTION,
args=[
Tool.Argument(
name="image",
type=DataType.IMAGE,
description="the image that need to be processed",
)
],
returns=[
Tool.Argument(
name="text",
type=DataType.TEXT,
description="the recognized text",
)
],
model=ocr,
),
]
GENERAL_TOOLS = [
Tool(
name="select_category",
description="select the target classes in category list with the given condition.",
domain=Tool.Domain.GENERAL,
usages=["pick out the objects with the same type"],
args=[
Tool.Argument(
name="category_list",
type=DataType.CATEGORY,
description="the list to be processed",
),
Tool.Argument(
name="condition",
type=DataType.TEXT,
description="the condition to select objects",
),
],
returns=[
Tool.Argument(
name="target_category_result",
type=DataType.CATEGORY,
description="the selected list",
)
],
model=select,
),
Tool(
name="select_bbox",
description="select the bounding boxes with the given condition.",
domain=Tool.Domain.GENERAL,
usages=["filter out the bounding boxes with the same type"],
args=[
Tool.Argument(
name="bbox_list",
type=DataType.BBOX,
description="the bounding box list to be processed",
),
Tool.Argument(
name="condition",
type=DataType.TEXT,
description="the condition to select objects",
),
],
returns=[
Tool.Argument(
name="result",
type=DataType.BBOX,
description="the selected bbox list",
)
],
model=select,
),
Tool(
name="select_mask",
description="select the masks with the given condition.",
domain=Tool.Domain.GENERAL,
args=[
Tool.Argument(
name="mask_list",
type=DataType.MASK,
description="the list to be processed",
),
Tool.Argument(
name="condition",
type=DataType.TEXT,
description="the condition to select objects",
),
],
returns=[
Tool.Argument(
name="result",
type=DataType.MASK,
description="the selected mask list",
)
],
model=select,
),
Tool(
name="count_categories",
description="count target categories in the given list.",
domain=Tool.Domain.GENERAL,
args=[
Tool.Argument(
name="category_list",
type=DataType.CATEGORY,
description="the list to be processed",
),
],
returns=[
Tool.Argument(
name="length",
type=DataType.TEXT,
description="the length of the given list, return in the string format."
"Example: The length of the given list is 10",
)
],
model=count,
),
Tool(
name="count_objects",
description="count target objects in the given list. It is useful when you want to count the number of objects in the image",
domain=Tool.Domain.GENERAL,
args=[
Tool.Argument(
name="bbox_list",
type=DataType.BBOX,
description="the bounding box list to be counted",
),
],
returns=[
Tool.Argument(
name="length",
type=DataType.TEXT,
description="the length of the given list, return in the string format."
"Example: The length of the given list is 10",
)
],
model=count,
),
Tool(
name="count_masks",
description="count target mask in the given list.",
domain=Tool.Domain.GENERAL,
args=[
Tool.Argument(
name="mask_list",
type=DataType.MASK,
description="the list to be processed",
),
],
returns=[
Tool.Argument(
name="length",
type=DataType.TEXT,
description="the length of the given list, return in the string format."
"Example: The length of the given list is 10",
)
],
model=count,
),
]
VIDEO_TOOLS = [
# VIDEO
Tool(
name="video_captioning",
description='Generate a caption or description for video. It can generate a detailed description that can be used for video perception and video generation. For example: a) you can use this tool when you want to know what happened in the video"; and b) when you want to generate tags for input video, you can use translate description obtained from `image_captioning` into tags.',
domain=Tool.Domain.VIDEO_PERCEPTION,
args=[
Tool.Argument(
name="video",
type=DataType.VIDEO,
description="the video to be captioned.",
),
],
returns=[
Tool.Argument(
name="caption",
type=DataType.TEXT,
description="the caption or description of input video.",
)
],
model=video_captioning,
),
Tool(
name="image_audio_to_video",
description="Generate a video with speech to introduce the image.",
domain=Tool.Domain.VIDEO_GENERATION,
args=[
Tool.Argument(
name="image",
type=DataType.IMAGE,
description="The input image to be introduced.",
),
Tool.Argument(
name="audio",
type=DataType.AUDIO,
description="The audio contained the speech of image description.",
),
],
returns=[
Tool.Argument(
name="video",
type=DataType.VIDEO,
description="Generated video that can introduce the image with speech",
)
],
model=image_audio_to_video,
),
Tool(
name="image_to_video",
description="Generate a video based on image.",
domain=Tool.Domain.VIDEO_GENERATION,
args=[
Tool.Argument(
name="image",
type=DataType.IMAGE,
description="The input image.",
),
],
returns=[
Tool.Argument(
name="video",
type=DataType.VIDEO,
description="Generated video from the input image.",
)
],
model=image_to_video,
),
Tool(
name="video_to_webpage",
description="Generate a web page to promote and introduce the video.",
domain=Tool.Domain.VIDEO_PROCESSING,
args=[
Tool.Argument(
name="video",
type=DataType.VIDEO,
description="The input image to be introduced.",
),
Tool.Argument(
name="title",
type=DataType.TITLE,
description="The title of video.",
),
Tool.Argument(
name="tags",
type=DataType.TAGS,
description="The tags of video.",
),
Tool.Argument(
name="description",
type=DataType.TEXT,
description="The description of video.",
),
],
returns=[
Tool.Argument(
name="html_code",
type=DataType.HTML,
description="Generated HTML webpage with code that can introduce the video with speech.",
)
],
model=video_to_webpage,
),
Tool(
name="dub_video",
description="Dub the input video with given audio track.",
domain=Tool.Domain.VIDEO_EDITING,
args=[
Tool.Argument(
name="video",
type=DataType.VIDEO,
description="The input image to be introduced.",
),
Tool.Argument(
name="audio",
type=DataType.AUDIO,
description="The audio of video.",
),
],
returns=[
Tool.Argument(
name="video",
type=DataType.VIDEO,
description="Output video with designated audio.",
)
],
model=dub_video,
),
Tool(
name="text_to_video",
description="It takes as input a natural language description and produces a video matching that description",
domain=Tool.Domain.VIDEO_GENERATION,
args=[
Tool.Argument(
name="prompt",
type=DataType.TEXT,
description="the text describing the image",
)
],
returns=[
Tool.Argument(
name="video",
type=DataType.VIDEO,
description="the generated video",
)
],
model=text_to_video,
),
]
AUDIO_TOOLS = [
# AUDIO
Tool(
name="text_to_music",
description="Generate music condioned on input text/prompt. For example, you can use this tool when you want to generate music for a poem, generate a piece of music from image.",
domain=Tool.Domain.AUDIO_GENERATION,
args=[
Tool.Argument(
name="text",
type=DataType.TEXT,
description="Input text for music generation.",
),
],
returns=[
Tool.Argument(
name="music",
type=DataType.AUDIO,
description="Generated music conditioned on text.",
)
],
model=text_to_music,
),
Tool(
name="text_to_speech",
description="Create natural-sounding speech from text, where the speech can be generated in multiple languages and for multiple speakers",
domain=Tool.Domain.AUDIO_GENERATION,
args=[
Tool.Argument(
name="text",
type=DataType.TEXT,
description="The input text that will be translated into speech.",
),
],
returns=[
Tool.Argument(
name="speech",
type=DataType.AUDIO,
description="Generated speech or voice conditioned on text.",
)
],
model=text_to_speech,
),
Tool(
name="audio_classification",
description="Audio classification is the task of assigning a label or class to a given audio. It can be used for recognizing which command a user is giving or the emotion of a statement, as well as identifying a speaker.",
domain=Tool.Domain.AUDIO_PERCEPTION,
args=[
Tool.Argument(
name="audio",
type=DataType.AUDIO,
description="The input audio that will be classified.",
),
],
returns=[
Tool.Argument(
name="speech",
type=DataType.CATEGORY,
description="The recognized categories in json format.",
)
],
model=audio_classification,
),
]
NLP_TOOLS = [
# Text
Tool(
name="text_to_text_generation",
description="Text to text generation. It can be used for sentence acceptability judgment, Sentiment analysis, Paraphrasing/sentence similarity, Natural language inference, Sentence completion, Word sense disambiguation, Question answering.",
domain=Tool.Domain.NATURAL_LANGUAGE_PROCESSING,
args=[
Tool.Argument(
name="text",
type=DataType.TEXT,
description="The input text",
),
],
returns=[
Tool.Argument(
name="answer",
type=DataType.TEXT,
description="Generated answer for given input.",
)
],
model=text_to_text_generation,
),
Tool(
name="title_generation",
description="Generate a title for given text.",
domain=Tool.Domain.NATURAL_LANGUAGE_PROCESSING,
args=[
Tool.Argument(
name="text",
type=DataType.TEXT,
description="The input text",
),
],
returns=[
Tool.Argument(
name="title",
type=DataType.TITLE,
description="Generated title based given sentences.",
)
],
model=title_generation,
),
Tool(
name="openai_chat_model",
description="Answer the question by Large Language Model.",
domain=Tool.Domain.QUESTION_ANSWERING,
args=[
Tool.Argument(
name="input_msg",
type=DataType.TEXT,
description="The input text",
)
],
returns=[
Tool.Argument(
name="answer",
type=DataType.TEXT,
description="Generated answer based given text.",
)
],
model=openai_chat_model,
),
Tool(
name="summarization",
description="Summarize sentences, long narratives, articles, papers, textbooks.",
domain=Tool.Domain.NATURAL_LANGUAGE_PROCESSING,
args=[
Tool.Argument(
name="text",
type=DataType.TEXT,
description="The input text to be Summarized.",
),
],
returns=[
Tool.Argument(
name="summarized_text",
type=DataType.TEXT,
description="Summarized text.",
)
],
model=summarization,
),
Tool(
name="text_to_tags",
description="Predict the tags of text, article and papers by using the their textual content as input",
domain=Tool.Domain.NATURAL_LANGUAGE_PROCESSING,
args=[
Tool.Argument(
name="text",
type=DataType.TEXT,
description="The input text to be Summarized.",
),
],
returns=[
Tool.Argument(
name="tags",
type=DataType.TAGS,
description="The extracted tags from input text",
)
],
model=text_to_tags,
),
Tool(
name="named_entity_recognition",
description="Named-entity recognition (NER) (also known as (named) entity identification, entity chunking, and entity extraction) is a subtask of information extraction that seeks to locate and classify named entities mentioned in unstructured text into pre-defined categories such as person names, organizations, locations, medical codes, time expressions, quantities, monetary values, percentages, etc.",
domain=Tool.Domain.NATURAL_LANGUAGE_PROCESSING,
args=[
Tool.Argument(
name="text",
type=DataType.TEXT,
description="The input text from which the named entities are extracted",
),
],
returns=[
Tool.Argument(
name="tags",
type=DataType.TAGS,
description="The extracted entities",
)
],
model=None,
),
Tool(
name="sentiment_analysis",
description="Sentiment analysis is the process of analyzing digital text to determine if the emotional tone of the message is positive, negative, or neutral.",
domain=Tool.Domain.NATURAL_LANGUAGE_PROCESSING,
args=[
Tool.Argument(
name="text",
type=DataType.TEXT,
description="The input text to be analyzed",
),
],
returns=[
Tool.Argument(
name="text",
type=DataType.TEXT,
description="The sentiment of text",
)
],
model=sentiment_analysis,
),
Tool(
name="extract_location",
description="Extracts the locale name from the text. For example, if the text is 'what is the weather in Beijing', the tool will return 'Beijing'. If the text is 'Samuel ppops in a happy plce called Berlin which happens to be Kazakhstan', the tool will return 'Berlin,Kazakhstan'.",
domain=Tool.Domain.NATURAL_LANGUAGE_PROCESSING,
args=[
Tool.Argument(
name="text",
type=DataType.TEXT,
description="The input text to be analyzed",
),
],
returns=[
Tool.Argument(
name="location",
type=DataType.LOCATION,
description="The sentiment of text",
)
],
model=extract_location,
),
Tool(
name="summarize_weather_condition",
description="Translate the json formatted weather information into the text that human can understand. For example, when you want to generate a new image based on weather information",
domain=Tool.Domain.NATURAL_LANGUAGE_PROCESSING,
args=[
Tool.Argument(
name="weather",
type=DataType.WEATHER,
description="weather condition",
)
],
returns=[
Tool.Argument(
name="weather_summary",
type=DataType.TEXT,
description="the weather summary",
)
],
model=summarize_weather_condition,
),
]
TOOLS = (
QUESTION_ANSWERING_TOOLS
+ IMAGE_CAPTIONING_TOOLS
+ IMAGE_EDITING_TOOLS
+ IMAGE_GENERATION_TOOLS
+ IMAGE_TRANSFORM_TOOLS
+ IMAGE_PERCEPTION_TOOLS
+ GENERAL_TOOLS
+ VIDEO_TOOLS
+ AUDIO_TOOLS
+ NLP_TOOLS
)
TOOLS = {tool.name: tool for tool in TOOLS}
if __name__ == "__main__":
tools = []
for tool in TOOLS.values():
tools.append(tool.dict())
import json
with open("tools.json", "w") as f:
json.dump(tools, f, indent=4)
|