Return textboxes on file upload errors (#214)
This commit is contained in:
		
							parent
							
								
									fdf4fe49ba
								
							
						
					
					
						commit
						a4ec1e5be3
					
				|  | @ -5,7 +5,7 @@ from smolagents import ( | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| agent = CodeAgent( | agent = CodeAgent( | ||||||
|     tools=[], model=HfApiModel(), max_steps=4, verbosity_level=0 |     tools=[], model=HfApiModel(), max_steps=4, verbosity_level=1 | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| GradioUI(agent, file_upload_folder='./data').launch() | GradioUI(agent, file_upload_folder='./data').launch() | ||||||
|  |  | ||||||
|  | @ -120,15 +120,21 @@ class GradioUI: | ||||||
|         """ |         """ | ||||||
| 
 | 
 | ||||||
|         if file is None: |         if file is None: | ||||||
|             return "No file uploaded" |             return gr.Textbox( | ||||||
|  |                 "No file uploaded", visible=True | ||||||
|  |             ), file_uploads_log | ||||||
| 
 | 
 | ||||||
|         try: |         try: | ||||||
|             mime_type, _ = mimetypes.guess_type(file.name) |             mime_type, _ = mimetypes.guess_type(file.name) | ||||||
|         except Exception as e: |         except Exception as e: | ||||||
|             return f"Error: {e}" |             return gr.Textbox( | ||||||
|  |                 f"Error: {e}", visible=True | ||||||
|  |             ), file_uploads_log | ||||||
| 
 | 
 | ||||||
|         if mime_type not in allowed_file_types: |         if mime_type not in allowed_file_types: | ||||||
|             return "File type disallowed" |             return gr.Textbox( | ||||||
|  |                 "File type disallowed", visible=True | ||||||
|  |             ), file_uploads_log | ||||||
| 
 | 
 | ||||||
|         # Sanitize file name |         # Sanitize file name | ||||||
|         original_name = os.path.basename(file.name) |         original_name = os.path.basename(file.name) | ||||||
|  | @ -181,7 +187,7 @@ class GradioUI: | ||||||
|             ) |             ) | ||||||
|             # If an upload folder is provided, enable the upload feature |             # If an upload folder is provided, enable the upload feature | ||||||
|             if self.file_upload_folder is not None: |             if self.file_upload_folder is not None: | ||||||
|                 upload_file = gr.File(label="Upload a file", height=1) |                 upload_file = gr.File(label="Upload a file") | ||||||
|                 upload_status = gr.Textbox( |                 upload_status = gr.Textbox( | ||||||
|                     label="Upload Status", interactive=False, visible=False |                     label="Upload Status", interactive=False, visible=False | ||||||
|                 ) |                 ) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue