Main entry point to access all observation processor
| 824 | |
| 825 | |
| 826 | class ObservationHandler: |
| 827 | """Main entry point to access all observation processor""" |
| 828 | |
| 829 | def __init__( |
| 830 | self, |
| 831 | main_observation_type: str, |
| 832 | text_observation_type: str, |
| 833 | image_observation_type: str, |
| 834 | current_viewport_only: bool, |
| 835 | viewport_size: ViewportSize, |
| 836 | ) -> None: |
| 837 | self.main_observation_type = main_observation_type |
| 838 | self.text_processor = TextObervationProcessor( |
| 839 | text_observation_type, current_viewport_only, viewport_size |
| 840 | ) |
| 841 | self.image_processor = ImageObservationProcessor( |
| 842 | image_observation_type |
| 843 | ) |
| 844 | self.viewport_size = viewport_size |
| 845 | |
| 846 | def get_observation_space(self) -> spaces.Dict: |
| 847 | text_space = spaces.Text( |
| 848 | min_length=0, |
| 849 | max_length=UTTERANCE_MAX_LENGTH, |
| 850 | charset=ASCII_CHARSET + FREQ_UNICODE_CHARSET, |
| 851 | ) |
| 852 | |
| 853 | image_space = spaces.Box( |
| 854 | # Each position stores the RGB values. Note the swapped axes (height first). |
| 855 | np.zeros( |
| 856 | (self.viewport_size["height"], self.viewport_size["width"], 3), |
| 857 | dtype=np.uint8, |
| 858 | ), |
| 859 | np.ones( |
| 860 | (self.viewport_size["height"], self.viewport_size["width"], 3), |
| 861 | dtype=np.uint8, |
| 862 | ) |
| 863 | * 255.0, |
| 864 | dtype=np.uint8, |
| 865 | ) |
| 866 | |
| 867 | return spaces.Dict({"text": text_space, "image": image_space}) |
| 868 | |
| 869 | def get_observation( |
| 870 | self, page: Page, client: CDPSession, context: str = '', |
| 871 | ) -> dict[str, Observation]: |
| 872 | text_obs = self.text_processor.process(page, client, context) |
| 873 | image_obs = self.image_processor.process(page, client, context) |
| 874 | return {"text": text_obs, "image": image_obs} |
| 875 | |
| 876 | def get_observation_metadata(self) -> dict[str, ObservationMetadata]: |
| 877 | return { |
| 878 | "text": self.text_processor.meta_data, |
| 879 | "image": self.image_processor.meta_data, |
| 880 | } |
| 881 | |
| 882 | @property |
| 883 | def action_processor(self) -> ObservationProcessor: |