File tree 1 file changed +24
-3
lines changed
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):
62
62
return temp_path
63
63
except Exception as e :
64
64
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
66
66
67
67
def create_gradio_app ():
68
68
"""Create the main Gradio application with all components"""
@@ -83,11 +83,32 @@ def create_gradio_app():
83
83
type = "filepath"
84
84
)
85
85
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
+
86
107
# Connect the components
87
108
capture_btn .click (
88
- fn = capture_and_show ,
109
+ fn = capture_with_error ,
89
110
inputs = [url_input ],
90
- outputs = [output_image ]
111
+ outputs = [output_image , error_output ]
91
112
)
92
113
93
114
return app
You can’t perform that action at this time.
0 commit comments