Spaces:
Running
on
Zero
Running
on
Zero
Fix app.py: Use exec() to properly execute gradio_app as __main__
Browse filesThe 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__'.
app.py
CHANGED
|
@@ -18,7 +18,9 @@ sys.argv = [
|
|
| 18 |
'--port', '7860'
|
| 19 |
]
|
| 20 |
|
| 21 |
-
#
|
| 22 |
-
#
|
| 23 |
if __name__ == '__main__':
|
| 24 |
-
|
|
|
|
|
|
|
|
|
| 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'})
|