minhho commited on
Commit
998bf82
·
1 Parent(s): 8978946

Fix app.py: Use exec() to properly execute gradio_app as __main__

Browse files

The import approach didn't work because gradio_app's
if __name__ == '__main__' block wouldn't execute when imported.
Using exec() ensures the code runs with __name__ set to '__main__'.

Files changed (1) hide show
  1. app.py +5 -3
app.py CHANGED
@@ -18,7 +18,9 @@ sys.argv = [
18
  '--port', '7860'
19
  ]
20
 
21
- # Import gradio_app to execute its if __name__ == '__main__' block
22
- # This is safe because we've already set sys.argv before import
23
  if __name__ == '__main__':
24
- import gradio_app
 
 
 
18
  '--port', '7860'
19
  ]
20
 
21
+ # Execute gradio_app.py as __main__ module
22
+ # We use exec() to run the code with __name__ == '__main__'
23
  if __name__ == '__main__':
24
+ with open('gradio_app.py', 'r') as f:
25
+ code = f.read()
26
+ exec(code, {'__name__': '__main__', '__file__': 'gradio_app.py'})