API Reference
Text
TextAnalyzer
Used to get text from a csv and then run the TextDetector on it.
Source code in ammico/text.py
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 | |
__init__(csv_path, column_key=None, csv_encoding='utf-8')
Init the TextTranslator class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
csv_path
|
str
|
Path to the CSV file containing the text entries. |
required |
column_key
|
str
|
Key for the column containing the text entries. Defaults to None. |
None
|
csv_encoding
|
str
|
Encoding of the CSV file. Defaults to "utf-8". |
'utf-8'
|
Source code in ammico/text.py
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 | |
read_csv()
Read the CSV file and return the dictionary with the text entries.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
The dictionary with the text entries. |
Source code in ammico/text.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 | |
TextDetector
Bases: AnalysisMethod
Source code in ammico/text.py
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 | |
__init__(subdict, skip_extraction=False, accept_privacy='PRIVACY_AMMICO')
Init text detection class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subdict
|
dict
|
Dictionary containing file name/path, and possibly previous analysis results from other modules. |
required |
skip_extraction
|
bool
|
Decide if text will be extracted from images or is already provided via a csv. Defaults to False. |
False
|
accept_privacy
|
str
|
Environment variable to accept the privacy statement for the Google Cloud processing of the data. Defaults to "PRIVACY_AMMICO". |
'PRIVACY_AMMICO'
|
Source code in ammico/text.py
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 | |
analyse_image()
Perform text extraction and analysis of the text.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
The updated dictionary with text analysis results. |
Source code in ammico/text.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | |
get_text_from_image()
Detect text on the image using Google Cloud Vision API.
Source code in ammico/text.py
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 | |
remove_linebreaks()
Remove linebreaks from original and translated text.
Source code in ammico/text.py
239 240 241 242 243 244 245 | |
set_keys()
Set the default keys for text analysis.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
The dictionary with default text keys. |
Source code in ammico/text.py
104 105 106 107 108 109 110 111 | |
translate_text()
Translate the detected text to English using the Translator object.
Source code in ammico/text.py
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | |
privacy_disclosure(accept_privacy='PRIVACY_AMMICO')
Asks the user to accept the privacy statement.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
accept_privacy
|
str
|
The name of the disclosure variable (default: "PRIVACY_AMMICO"). |
'PRIVACY_AMMICO'
|
Source code in ammico/text.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | |
Image Summary
ImageSummaryDetector
Bases: AnalysisMethod
Source code in ammico/image_summary.py
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 | |
__init__(summary_model, subdict=None)
Class for analysing images using QWEN-2.5-VL model. It provides methods for generating captions and answering questions about images.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
summary_model
|
[type]
|
An instance of MultimodalSummaryModel to be used for analysis. |
required |
subdict
|
dict
|
Dictionary containing the image to be analysed. Defaults to {}. |
None
|
Returns:
| Type | Description |
|---|---|
None
|
None. |
Source code in ammico/image_summary.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
analyse_image(entry, analysis_type=AnalysisType.SUMMARY_AND_QUESTIONS, list_of_questions=None, max_questions_per_image=MAX_QUESTIONS_PER_IMAGE, is_concise_summary=True, is_concise_answer=True)
Analyse a single image entry. Returns dict with keys depending on analysis_type: - 'caption' (str) if summary requested - 'vqa' (dict) if questions requested
Source code in ammico/image_summary.py
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 | |
analyse_images_from_dict(analysis_type=AnalysisType.SUMMARY_AND_QUESTIONS, list_of_questions=None, max_questions_per_image=MAX_QUESTIONS_PER_IMAGE, keys_batch_size=KEYS_BATCH_SIZE, is_concise_summary=True, is_concise_answer=True)
Analyse image with model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
analysis_type
|
str
|
type of the analysis. |
SUMMARY_AND_QUESTIONS
|
list_of_questions
|
list[str]
|
list of questions. |
None
|
max_questions_per_image
|
int
|
maximum number of questions per image. We recommend to keep it low to avoid long processing times and high memory usage. |
MAX_QUESTIONS_PER_IMAGE
|
keys_batch_size
|
int
|
number of images to process in a batch. |
KEYS_BATCH_SIZE
|
is_concise_summary
|
bool
|
whether to generate concise summary. |
True
|
is_concise_answer
|
bool
|
whether to generate concise answers. |
True
|
Returns: self.subdict (dict): dictionary with analysis results.
Source code in ammico/image_summary.py
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 | |
answer_questions(list_of_questions, entry=None, is_concise_answer=True)
Create answers for list of questions about image. Args: list_of_questions (list[str]): list of questions. entry (dict): dictionary containing the image to be captioned. is_concise_answer (bool): whether to generate concise answers. Returns: answers (list[str]): list of answers.
Source code in ammico/image_summary.py
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 | |
generate_caption(entry=None, num_return_sequences=1, is_concise_summary=True)
Create caption for image. Depending on is_concise_summary it will be either concise or detailed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entry
|
dict
|
dictionary containing the image to be captioned. |
None
|
num_return_sequences
|
int
|
number of captions to generate. |
1
|
is_concise_summary
|
bool
|
whether to generate concise summary. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
results |
list[str]
|
list of generated captions. |
Source code in ammico/image_summary.py
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 | |
Video Summary
VideoSummaryDetector
Bases: AnalysisMethod
Source code in ammico/video_summary.py
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 | |
__init__(summary_model=None, audio_model=None, subdict=None)
Class for analysing videos using QWEN-2.5-VL model. It provides methods for generating captions and answering questions about videos.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
summary_model
|
[type]
|
An instance of MultimodalSummaryModel to be used for analysis. |
None
|
subdict
|
dict
|
Dictionary containing the video to be analysed. Defaults to {}. |
None
|
Returns:
| Type | Description |
|---|---|
None
|
None. |
Source code in ammico/video_summary.py
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 | |
analyse_videos_from_dict(analysis_type=AnalysisType.SUMMARY, list_of_questions=None)
Analyse the video specified in self.subdict using frame extraction and captioning. Args: analysis_type (Union[AnalysisType, str], optional): Type of analysis to perform. Defaults to AnalysisType.SUMMARY. list_of_questions (List[str], optional): List of questions to answer about the video. Required if analysis_type includes questions. Returns: Dict[str, Any]: A dictionary containing the analysis results, including summary and answers for provided questions(if any).
Source code in ammico/video_summary.py
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 | |
final_answers(answers_dict, list_of_questions)
Answer the list of questions for the video based on the VQA bullets from the frames. Args: answers_dict (Dict[str, Any]): Dictionary containing the VQA bullets. Returns: Dict[str, Any]: A dictionary containing the list of answers to the questions.
Source code in ammico/video_summary.py
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 | |
final_summary(summary_dict)
Produce a concise summary of the video, based on generated captions for all extracted frames. Args: summary_dict (Dict[str, Any]): Dictionary containing captions for the frames. Returns: Dict[str, Any]: A dictionary containing the list of captions with timestamps and the final summary.
Source code in ammico/video_summary.py
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 | |
make_captions_for_subclips(entry, list_of_questions=None)
Generate captions for video subclips using both audio and visual information, for a further full video summary/VQA. Args: entry (Dict[str, Any]): Dictionary containing the video file information. list_of_questions (Optional[List[str]]): List of questions for VQA. Returns: List[Dict[str, Any]]: List of dictionaries containing timestamps and generated captions.
Source code in ammico/video_summary.py
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 | |
merge_audio_visual_boundaries(audio_segs, video_segs, segment_threshold_duration=8)
Merge audio phrase boundaries and video scene cuts into coherent temporal segments for the model Args: audio_segs: List of audio segments with 'start_time' and 'end_time' video_segs: List of video segments with 'start_time' and 'end_time' segment_threshold_duration: Duration to create a new segment boundary Returns: List of merged segments
Source code in ammico/video_summary.py
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 | |
Colors
ColorDetector
Bases: AnalysisMethod
Source code in ammico/colors.py
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 | |
__init__(subdict, delta_e_method='CIE 1976')
Color Analysis class, analyse hue and identify named colors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subdict
|
dict
|
The dictionary containing the image path. |
required |
delta_e_method
|
str
|
The calculation method used for assigning the closest color name, defaults to "CIE 1976". The available options are: 'CIE 1976', 'CIE 1994', 'CIE 2000', 'CMC', 'ITP', 'CAM02-LCD', 'CAM02-SCD', 'CAM02-UCS', 'CAM16-LCD', 'CAM16-SCD', 'CAM16-UCS', 'DIN99' |
'CIE 1976'
|
Source code in ammico/colors.py
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 | |
analyse_image()
Uses the colorgram library to extract the n most common colors from the images. One problem is, that the most common colors are taken before beeing categorized, so for small values it might occur that the ten most common colors are shades of grey, while other colors are present but will be ignored. Because of this n_colors=100 was chosen as default.
The colors are then matched to the closest color in the CSS3 color list using the delta-e metric. They are then merged into one data frame. The colors can be reduced to a smaller list of colors using the get_color_table function. These colors are: "red", "green", "blue", "yellow","cyan", "orange", "purple", "pink", "brown", "grey", "white", "black".
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
Dictionary with color names as keys and percentage of color in image as values. |
Source code in ammico/colors.py
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 | |
rgb2name(c, merge_color=True, delta_e_method='CIE 1976')
Take an rgb color as input and return the closest color name from the CSS3 color list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
c
|
Union[List, tuple]
|
RGB value. |
required |
merge_color
|
(bool, Optional)
|
Whether color name should be reduced, defaults to True. |
True
|
Returns: str: Closest matching color name.
Source code in ammico/colors.py
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 | |
Utils
AnalysisMethod
Base class to be inherited by all analysis methods.
Source code in ammico/utils.py
85 86 87 88 89 90 91 92 93 94 95 96 | |
DownloadResource
A remote resource that needs on demand downloading.
We use this as a wrapper to the pooch library. The wrapper registers each data file and allows prefetching through the CLI entry point ammico_prefetch_models.
Source code in ammico/utils.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | |
ammico_prefetch_models()
Prefetch all the download resources
Source code in ammico/utils.py
44 45 46 47 | |
append_data_to_dict(mydict)
Append entries from nested dictionaries to keys in a global dict.
Source code in ammico/utils.py
438 439 440 441 442 443 444 445 446 447 | |
dump_df(mydict)
Utility to dump the dictionary into a dataframe.
Source code in ammico/utils.py
450 451 452 | |
find_files(path=None, pattern=None, recursive=True, limit=20, random_seed=None, return_as_list=False)
Find image files on the file system.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The base directory where we are looking for the images. Defaults to None, which uses the ammico data directory if set or the current working directory otherwise. |
None
|
pattern
|
str | list
|
The naming pattern that the filename should match. Use either '.ext' or just 'ext' Defaults to ["png", "jpg", "jpeg", "gif", "webp", "avif","tiff"]. Can be used to allow other patterns or to only include specific prefixes or suffixes. |
None
|
recursive
|
bool
|
Whether to recurse into subdirectories. Default is set to True. |
True
|
limit
|
int / list
|
The maximum number of images to be found. Provide a list or tuple of length 2 to batch the images. Defaults to 20. To return all images, set to None or -1. |
20
|
random_seed
|
int
|
The random seed to use for shuffling the images. If None is provided the data will not be shuffeled. Defaults to None. |
None
|
return_as_list
|
bool
|
Whether to return the list of files instead of a dict. Defaults to False. |
False
|
Returns: dict: A nested dictionary with file ids and all filenames including the path. Or list: A list of file paths if return_as_list is set to True.
Source code in ammico/utils.py
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 | |
find_videos(path=None, pattern=['mp4', 'mov', 'avi', 'mkv', 'webm'], recursive=True, limit=5, random_seed=None)
Find video files on the file system.
Source code in ammico/utils.py
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 | |
get_supported_whisperx_languages()
Get the list of supported whisperx languages.
Source code in ammico/utils.py
483 484 485 486 487 488 | |
initialize_dict(filelist)
Initialize the nested dictionary for all the found images.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filelist
|
list
|
The list of files to be analyzed, including their paths. |
required |
Returns: dict: The nested dictionary with all image ids and their paths.
Source code in ammico/utils.py
376 377 378 379 380 381 382 383 384 385 386 387 | |
is_interactive()
Check if we are running in an interactive environment.
Source code in ammico/utils.py
461 462 463 464 465 | |
load_image(image_path)
Load image from file path or return if already PIL Image.
Source code in ammico/utils.py
491 492 493 494 495 496 497 498 499 500 | |
prepare_image(image, target_size=(512, 512), resize_mode='resize')
Prepare image for model input with optimal resolution.
Source code in ammico/utils.py
503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 | |
Display
AnalysisExplorer
Source code in ammico/display.py
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 | |
__init__(mydict)
Initialize the AnalysisExplorer class to create an interactive visualization of the analysis results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mydict
|
dict
|
A nested dictionary containing image data for all images. |
required |
Source code in ammico/display.py
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 | |
run_server(port=8050)
Run the Dash server to start the analysis explorer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
port
|
int
|
The port number to run the server on (default: 8050). |
8050
|
Source code in ammico/display.py
329 330 331 332 333 334 335 336 337 | |
update_picture(img_path)
Callback function to update the displayed image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img_path
|
str
|
The path of the selected image. |
required |
Returns:
| Type | Description |
|---|---|
Optional[Image]
|
Union[PIL.PngImagePlugin, None]: The image object to be displayed or None if the image path is |
Source code in ammico/display.py
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 | |
Model
AudioToTextModel
Source code in ammico/model.py
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 | |
__init__(model_size='large', device=None, language=None)
Class for WhisperX model loading and inference. Args: model_size: Size of Whisper model to load (small, base, large). device: "cuda" or "cpu" (auto-detected when None). language: ISO-639-1 language code (e.g., "en", "fr", "de"). If None, language will be detected automatically. Set this to avoid unreliable detection on small clips.
Source code in ammico/model.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | |
close()
Free model resources (helpful in long-running processes).
Source code in ammico/model.py
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | |
MultimodalEmbeddingsModel
Source code in ammico/model.py
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 | |
__init__(device=None)
Class for Multimodal Embeddings model loading and inference. Uses Jina CLIP-V2 model. Args: device: "cuda" or "cpu" (auto-detected when None).
Source code in ammico/model.py
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | |
close()
Free model resources (helpful in long-running processes).
Source code in ammico/model.py
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 | |
MultimodalSummaryModel
Source code in ammico/model.py
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 | |
__init__(model_id=None, device=None, cache_dir=None)
Class for QWEN-2.5-VL model loading and inference. Args: model_id: Type of model to load, defaults to a smaller version for CPU if device is "cpu". device: "cuda" or "cpu" (auto-detected when None). cache_dir: huggingface cache dir (optional).
Source code in ammico/model.py
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 | |
close()
Free model resources (helpful in long-running processes).
Source code in ammico/model.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | |
Prompt Builder
ProcessingLevel
Bases: Enum
Define the three processing levels in a pipeline. FRAME: individual frame analysis CLIP: video segment (multiple frames) VIDEO: full video (multiple clips)
Source code in ammico/prompt_builder.py
5 6 7 8 9 10 11 12 13 | |
PromptBuilder
Modular prompt builder for multi-level video analysis. Handles frame-level, clip-level, and video-level prompts.
Source code in ammico/prompt_builder.py
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 | |
audio_module(audio_transcription)
staticmethod
Audio transcription with timestamps.
Source code in ammico/prompt_builder.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
build_clip_prompt(frame_bullets, include_audio=False, audio_transcription=None, include_vqa=False, questions=None, vqa_bullets=None)
classmethod
Build prompt for clip-level analysis.
Source code in ammico/prompt_builder.py
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 | |
build_frame_prompt(include_vqa=False, questions=None)
classmethod
Build prompt for frame-level analysis.
Source code in ammico/prompt_builder.py
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | |
build_video_prompt(include_vqa=False, clip_summaries=None, questions=None, vqa_bullets=None)
classmethod
Build prompt for video-level analysis.
Source code in ammico/prompt_builder.py
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 | |
questions_module(questions)
staticmethod
Format questions list.
Source code in ammico/prompt_builder.py
179 180 181 182 183 184 185 186 187 188 189 | |
summary_task(has_audio=False)
staticmethod
Generate summary task (with or without audio).
Source code in ammico/prompt_builder.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | |
summary_vqa_task(level, has_audio=False)
staticmethod
Generate summary+VQA task (adapts based on level and audio). For Frame and Clip levels.
Source code in ammico/prompt_builder.py
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 | |
visual_captions_final_module(clip_summaries)
staticmethod
For video-level processing with clip summaries.
Source code in ammico/prompt_builder.py
57 58 59 60 61 62 63 64 65 66 67 | |
visual_captions_module(frame_bullets)
staticmethod
For clip-level processing with frame summaries.
Source code in ammico/prompt_builder.py
44 45 46 47 48 49 50 51 52 53 54 55 | |
visual_frames_module()
staticmethod
For frame-level processing with actual images.
Source code in ammico/prompt_builder.py
36 37 38 39 40 41 42 | |
vqa_context_module(vqa_bullets, is_final=False)
staticmethod
VQA context (frame-level or clip-level answers).
Source code in ammico/prompt_builder.py
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
vqa_only_task()
staticmethod
VQA-only task for video-level processing.
Source code in ammico/prompt_builder.py
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | |