Codingacademey commited on
Commit
5de07fb
·
1 Parent(s): 12264ee

Add application file

Browse files
Files changed (1) hide show
  1. app.py +13 -1
app.py CHANGED
@@ -267,6 +267,18 @@ def main() -> None:
267
 
268
 
269
  if __name__ == "__main__":
270
- main()
 
 
 
 
 
 
 
 
 
 
 
 
271
 
272
 
 
267
 
268
 
269
  if __name__ == "__main__":
270
+ # When run via `streamlit run`, a ScriptRunContext exists. If not, avoid calling
271
+ # Streamlit APIs directly to prevent "missing ScriptRunContext" warnings/errors.
272
+ try:
273
+ from streamlit.runtime.scriptrunner import get_script_run_ctx # type: ignore
274
+
275
+ if get_script_run_ctx() is not None:
276
+ main()
277
+ else:
278
+ print("This app must be started with: streamlit run Image_Compressor/app.py")
279
+ except Exception:
280
+ # Older/newer Streamlit versions may not expose get_script_run_ctx.
281
+ # Fallback: advise the correct launch command.
282
+ print("This app must be started with: streamlit run Image_Compressor/app.py")
283
 
284