@@ -57,7 +57,7 @@ def execute(self, data: pd.DataFrame, proc_info: ProcStatement, dataset_manager=
5757 Returns:
5858 Dictionary containing results and output data
5959 """
60- results = {
60+ results : Dict [ str , Any ] = {
6161 'output_text' : [],
6262 'output_data' : None
6363 }
@@ -122,6 +122,11 @@ def execute(self, data: pd.DataFrame, proc_info: ProcStatement, dataset_manager=
122122
123123 def _generate_text (self , prompt : str , model : str ) -> Dict [str , Any ]:
124124 """Generate text using the Hugging Face model."""
125+ if self .generator is None :
126+ return {
127+ 'output' : ["ERROR: Language model not initialized." ],
128+ 'data' : None
129+ }
125130 try :
126131 # Generate text using the pipeline
127132 result = self .generator (
@@ -161,6 +166,11 @@ def _generate_text(self, prompt: str, model: str) -> Dict[str, Any]:
161166
162167 def _question_answer (self , question : str , context : str , model : str ) -> Dict [str , Any ]:
163168 """Answer questions using the model."""
169+ if self .generator is None :
170+ return {
171+ 'output' : ["ERROR: Language model not initialized." ],
172+ 'data' : None
173+ }
164174 try :
165175 # For Q&A, we'll use text generation with a structured prompt
166176 if context :
@@ -208,6 +218,11 @@ def _question_answer(self, question: str, context: str, model: str) -> Dict[str,
208218
209219 def _summarize_text (self , text : str , model : str ) -> Dict [str , Any ]:
210220 """Summarize text using the model."""
221+ if self .generator is None :
222+ return {
223+ 'output' : ["ERROR: Language model not initialized." ],
224+ 'data' : None
225+ }
211226 try :
212227 summary_prompt = f"Summarize the following text:\n \n { text } \n \n Summary:"
213228
@@ -249,6 +264,11 @@ def _summarize_text(self, text: str, model: str) -> Dict[str, Any]:
249264
250265 def _analyze_text (self , text : str , model : str ) -> Dict [str , Any ]:
251266 """Analyze text using the model."""
267+ if self .generator is None :
268+ return {
269+ 'output' : ["ERROR: Language model not initialized." ],
270+ 'data' : None
271+ }
252272 try :
253273 analysis_prompt = f"Analyze the following text and provide insights:\n \n { text } \n \n Analysis:"
254274
@@ -290,6 +310,11 @@ def _analyze_text(self, text: str, model: str) -> Dict[str, Any]:
290310
291311 def _summarize_data (self , data : pd .DataFrame , var_vars : List [str ], prompt : str , model : str ) -> Dict [str , Any ]:
292312 """Summarize data using the model."""
313+ if self .generator is None :
314+ return {
315+ 'output' : ["ERROR: Language model not initialized." ],
316+ 'data' : None
317+ }
293318 try :
294319 # Create a text description of the data
295320 data_desc = f"Dataset with { len (data )} rows and { len (data .columns )} columns."
@@ -337,6 +362,11 @@ def _summarize_data(self, data: pd.DataFrame, var_vars: List[str], prompt: str,
337362
338363 def _analyze_data (self , data : pd .DataFrame , var_vars : List [str ], prompt : str , model : str ) -> Dict [str , Any ]:
339364 """Analyze data using the model."""
365+ if self .generator is None :
366+ return {
367+ 'output' : ["ERROR: Language model not initialized." ],
368+ 'data' : None
369+ }
340370 try :
341371 # Create a text description of the data
342372 data_desc = f"Dataset with { len (data )} rows and { len (data .columns )} columns."
0 commit comments