Gregniuki commited on
Commit
57989d0
·
verified ·
1 Parent(s): 4c0c0cc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -5
app.py CHANGED
@@ -1,23 +1,31 @@
1
  import subprocess
2
  import gradio as gr
 
3
 
 
4
  def install_package():
5
- # Clone the Mario game repository (if not already cloned)
6
  subprocess.run(["git", "clone", "https://github.com/reruns/mario.git", "mario"], check=True)
7
 
8
  # Install the game files on startup
9
  install_package()
10
 
11
- # Define a function to serve the game
 
 
 
 
 
 
 
 
12
  def serve_game():
13
- # Read the index.html file from the cloned repository
14
  with open("mario/index.html", "r") as file:
15
  html_content = file.read()
16
  return html_content
17
 
18
  # Create a Gradio interface
19
  iface = gr.Interface(
20
- fn=serve_game, # Use the serve_game function to generate the HTML content
21
  inputs=None, # No inputs needed
22
  outputs=gr.HTML(), # Output is HTML content
23
  live=True, # Keep the interface live
@@ -26,4 +34,4 @@ iface = gr.Interface(
26
  )
27
 
28
  # Launch the Gradio app
29
- iface.launch()
 
1
  import subprocess
2
  import gradio as gr
3
+ from flask import Flask, send_from_directory
4
 
5
+ # Clone the Mario game repository
6
  def install_package():
 
7
  subprocess.run(["git", "clone", "https://github.com/reruns/mario.git", "mario"], check=True)
8
 
9
  # Install the game files on startup
10
  install_package()
11
 
12
+ # Create a Flask app to serve static files
13
+ flask_app = Flask(__name__)
14
+
15
+ # Serve static files (JavaScript, CSS, assets, etc.)
16
+ @flask_app.route("/mario/<path:path>")
17
+ def serve_static(path):
18
+ return send_from_directory("mario", path)
19
+
20
+ # Read the index.html file
21
  def serve_game():
 
22
  with open("mario/index.html", "r") as file:
23
  html_content = file.read()
24
  return html_content
25
 
26
  # Create a Gradio interface
27
  iface = gr.Interface(
28
+ fn=serve_game, # Function to generate the HTML content
29
  inputs=None, # No inputs needed
30
  outputs=gr.HTML(), # Output is HTML content
31
  live=True, # Keep the interface live
 
34
  )
35
 
36
  # Launch the Gradio app
37
+ iface.launch(server_name="0.0.0.0", server_port=7860)