File tree Expand file tree Collapse file tree 1 file changed +24
-3
lines changed
Expand file tree Collapse file tree 1 file changed +24
-3
lines changed Original file line number Diff line number Diff line change @@ -62,7 +62,7 @@ def capture_and_show(url: str):
6262 return temp_path
6363 except Exception as e :
6464 print (f"Error in capture_and_show: { str (e )} " ) # Add detailed logging
65- return f"Error capturing page: { str ( e ) } "
65+ return None # Return None instead of error string to handle gracefully
6666
6767def create_gradio_app ():
6868 """Create the main Gradio application with all components"""
@@ -83,11 +83,32 @@ def create_gradio_app():
8383 type = "filepath"
8484 )
8585
86+ error_output = gr .Textbox (
87+ label = "Error Message" ,
88+ visible = False ,
89+ interactive = False
90+ )
91+
92+ def capture_with_error (url ):
93+ try :
94+ # Basic URL validation
95+ if not url :
96+ return None , gr .update (visible = True , value = "Please enter a URL" )
97+ if not url .startswith (('http://' , 'https://' )):
98+ return None , gr .update (visible = True , value = "Please enter a valid URL starting with http:// or https://" )
99+
100+ result = capture_and_show (url )
101+ if result is None :
102+ return None , gr .update (visible = True , value = "Failed to capture screenshot. Please check the URL and try again." )
103+ return result , gr .update (visible = False , value = "" )
104+ except Exception as e :
105+ return None , gr .update (visible = True , value = f"Error: { str (e )} " )
106+
86107 # Connect the components
87108 capture_btn .click (
88- fn = capture_and_show ,
109+ fn = capture_with_error ,
89110 inputs = [url_input ],
90- outputs = [output_image ]
111+ outputs = [output_image , error_output ]
91112 )
92113
93114 return app
You can’t perform that action at this time.
0 commit comments