Gregniuki commited on
Commit
701daab
·
verified ·
1 Parent(s): 0a6e204

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -4
app.py CHANGED
@@ -3,6 +3,7 @@ from flask import Flask, send_from_directory
3
  from flask_cors import CORS
4
  import gradio as gr
5
  import threading
 
6
 
7
  # Set the temporary directory for Gradio to a writable location
8
  os.environ["GRADIO_TEMP_DIR"] = "/tmp"
@@ -11,6 +12,9 @@ os.environ["GRADIO_TEMP_DIR"] = "/tmp"
11
  flask_app = Flask(__name__)
12
  CORS(flask_app) # Enable CORS
13
 
 
 
 
14
  # Serve the Mario game files
15
  @flask_app.route("/mario")
16
  def serve_index():
@@ -24,14 +28,16 @@ def serve_static(path):
24
  # Debug route to list files
25
  @flask_app.route("/mario/files")
26
  def list_files():
27
- import os
28
  files = os.listdir("/app/mario")
29
  return {"files": files}
30
 
31
  # Run Flask in a separate thread
32
  def run_flask():
33
- print("Starting Flask server...")
34
- flask_app.run(host="0.0.0.0", port=5000)
 
 
 
35
 
36
  flask_thread = threading.Thread(target=run_flask)
37
  flask_thread.daemon = True
@@ -54,4 +60,8 @@ iface = gr.Interface(
54
  )
55
 
56
  # Launch the Gradio app
57
- iface.launch(server_name="0.0.0.0", server_port=7860)
 
 
 
 
 
3
  from flask_cors import CORS
4
  import gradio as gr
5
  import threading
6
+ import logging
7
 
8
  # Set the temporary directory for Gradio to a writable location
9
  os.environ["GRADIO_TEMP_DIR"] = "/tmp"
 
12
  flask_app = Flask(__name__)
13
  CORS(flask_app) # Enable CORS
14
 
15
+ # Configure logging
16
+ logging.basicConfig(level=logging.INFO)
17
+
18
  # Serve the Mario game files
19
  @flask_app.route("/mario")
20
  def serve_index():
 
28
  # Debug route to list files
29
  @flask_app.route("/mario/files")
30
  def list_files():
 
31
  files = os.listdir("/app/mario")
32
  return {"files": files}
33
 
34
  # Run Flask in a separate thread
35
  def run_flask():
36
+ try:
37
+ logging.info("Starting Flask server...")
38
+ flask_app.run(host="0.0.0.0", port=5000)
39
+ except Exception as e:
40
+ logging.error(f"Failed to start Flask server: {e}")
41
 
42
  flask_thread = threading.Thread(target=run_flask)
43
  flask_thread.daemon = True
 
60
  )
61
 
62
  # Launch the Gradio app
63
+ try:
64
+ logging.info("Starting Gradio interface...")
65
+ iface.launch(server_name="0.0.0.0", server_port=7860)
66
+ except Exception as e:
67
+ logging.error(f"Failed to start Gradio interface: {e}")