@@ -58,9 +58,7 @@ def __init__(self, model_name="facebook/bart-large-cnn"):
5858 ) # nosec B615
5959
6060 def process_text (self , text , max_length = 25 , num_beams = 5 ):
61- """
62- Method process_text.
63- """
61+ """Process and summarize the given text using a model."""
6462 logging .info ("Processing text for summarization" )
6563 try :
6664 inputs = self .tokenizer (
@@ -119,9 +117,7 @@ def preprocess_large_image(image_path, max_size=(2000, 2000)):
119117 return None
120118
121119 def process_image (self , image_path ):
122- """
123- Method process_image.
124- """
120+ """Process an image for classification."""
125121 logging .info ("Processing image for classification" )
126122 try :
127123 image_path = self .preprocess_large_image (
@@ -156,9 +152,7 @@ def __init__(self):
156152 )
157153
158154 def process_image (self , image_path ):
159- """
160- Method process_image.
161- """
155+ """Process an image for classification with augmentation."""
162156 logging .info ("Processing image with augmentation for classification" )
163157 try :
164158 image_path = self .preprocess_large_image (
@@ -227,16 +221,12 @@ def __init__(self):
227221 self .state = 50
228222
229223 def reset (self ):
230- """
231- Method reset.
232- """
224+ """Resets the state to 50 and returns it as a numpy array."""
233225 self .state = 50
234226 return np .array ([self .state ], dtype = np .float32 )
235227
236228 def step (self , action ):
237- """
238- Method step.
239- """
229+ """Executes a step in the environment based on the given action."""
240230 reward = - abs (self .state - (50 + action * 10 ))
241231 self .state += action - 2
242232 done = self .state <= 0 or self .state >= 100
@@ -256,9 +246,7 @@ def __init__(self):
256246 self .model = PPO ("MlpPolicy" , self .env , verbose = 1 )
257247
258248 def train (self , timesteps = 10000 ):
259- """
260- Method train.
261- """
249+ """Trains the RL model for a specified number of timesteps."""
262250 logging .info ("Training RL model" )
263251 try :
264252 self .model .learn (total_timesteps = timesteps )
@@ -267,9 +255,7 @@ def train(self, timesteps=10000):
267255 logging .error (f"Error in RLModule training: { e } " )
268256
269257 def save_model (self , path ):
270- """
271- Method save_model.
272- """
258+ """Saves the model to the specified path."""
273259 try :
274260 self .model .save (path )
275261 logging .info (f"Model saved to { path } " )
@@ -341,9 +327,7 @@ def extract_frames(
341327 return frame_count
342328
343329 def process_frame (self , frame_path ):
344- """
345- Method process_frame.
346- """
330+ """Processes an image frame and returns a tensor."""
347331 try :
348332 image = Image .open (frame_path ).convert ("RGB" )
349333 tensor = self .transform (image ).unsqueeze (0 )
@@ -365,8 +349,17 @@ def __init__(self):
365349 super ().__init__ ()
366350
367351 def process_real_time_video (self , source = 0 ):
368- """
369- Method process_real_time_video.
352+ """Process real-time video from a specified source.
353+
354+ This method captures video from the given source and processes each frame in
355+ real-time. It checks if the video source is opened successfully, and if not,
356+ logs an error. The frames are resized and transformed before being displayed
357+ in a window. The processing continues until the video ends or the user presses
358+ the 'q' key to quit. Finally, it releases the video capture and closes all
359+ OpenCV windows.
360+
361+ Args:
362+ source (int or str): The video source, which can be an integer for
370363 """
371364 cap = cv2 .VideoCapture (source )
372365 if not cap .isOpened ():
@@ -401,9 +394,7 @@ def __init__(self):
401394 self .engine = pyttsx3 .init ()
402395
403396 def speech_to_text (self , audio_file ):
404- """
405- Method speech_to_text.
406- """
397+ """Converts speech from an audio file to text."""
407398 try :
408399 with sr .AudioFile (audio_file ) as source :
409400 audio = self .recognizer .record (source )
@@ -443,9 +434,7 @@ def __init__(self):
443434 self .voice_processor = VoiceProcessor ()
444435
445436 def process_input (self , text = None , image_path = None ):
446- """
447- Method process_input.
448- """
437+ """Processes text and image input and returns the results."""
449438 results = {}
450439 if text :
451440 results ["nlp" ] = self .nlp .process_text (text )
@@ -454,25 +443,19 @@ def process_input(self, text=None, image_path=None):
454443 return results
455444
456445 def process_multi_modal (self , text , image_path ):
457- """
458- Method process_multi_modal.
459- """
446+ """Processes text and image using multi-modal processing."""
460447 return self .multi_modal .process_text_image (text , image_path )
461448
462449 def process_video (self , video_path , frame_output_dir ):
463- """
464- Method process_video.
465- """
450+ """Process a video and extract its frames."""
466451 frame_count = self .video_processor .extract_frames (video_path , frame_output_dir )
467452 if frame_count == 0 :
468453 logging .error ("No frames were saved. Please check the video file and path." )
469454 return
470455 logging .info (f"Video frames processed and saved to { frame_output_dir } " )
471456
472457 def process_real_time_video (self , source = 0 ):
473- """
474- Method process_real_time_video.
475- """
458+ """Processes real-time video from the specified source."""
476459 self .real_time_video_processor .process_real_time_video (source )
477460
478461 def train_rl (self , timesteps = 10000 ):
@@ -482,15 +465,11 @@ def train_rl(self, timesteps=10000):
482465 self .rl .train (timesteps )
483466
484467 def choose_action (self , state ):
485- """
486- Method choose_action.
487- """
468+ """Selects an action based on the given state."""
488469 return self .rl .choose_action (state )
489470
490471 def visualize_data (self , data ):
491- """
492- Method visualize_data.
493- """
472+ """Visualizes the given data using a bar chart."""
494473 try :
495474 fig = px .bar (
496475 x = list (data .keys ()), y = list (data .values ()), title = "Data Visualization"
@@ -500,15 +479,11 @@ def visualize_data(self, data):
500479 logging .error (f"Error in data visualization: { e } " )
501480
502481 def speech_to_text (self , audio_file ):
503- """
504- Method speech_to_text.
505- """
482+ """Converts speech from an audio file to text."""
506483 return self .voice_processor .speech_to_text (audio_file )
507484
508485 def text_to_speech (self , text ):
509- """
510- Method text_to_speech.
511- """
486+ """Converts text to speech using the voice processor."""
512487 self .voice_processor .text_to_speech (text )
513488
514489
0 commit comments