Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,9 @@
|
|
1 |
import subprocess
|
2 |
import sys
|
3 |
import gradio as gr
|
|
|
|
|
|
|
4 |
|
5 |
# Install Flask if not already installed
|
6 |
def install_flask():
|
@@ -13,34 +16,40 @@ def install_flask():
|
|
13 |
install_flask()
|
14 |
|
15 |
# Clone the Mario game repository
|
16 |
-
import os
|
17 |
-
|
18 |
def install_package():
|
19 |
-
|
|
|
20 |
index_html_path = os.path.abspath("mario/index.html") # Get absolute path
|
21 |
print(f"Index.html is located at: {index_html_path}") # Debugging
|
22 |
return index_html_path
|
|
|
23 |
install_package()
|
24 |
-
# Now import Flask
|
25 |
-
from flask import Flask, send_from_directory
|
26 |
|
27 |
# Create a Flask app to serve static files
|
28 |
flask_app = Flask(__name__)
|
|
|
29 |
@flask_app.route("/mario")
|
30 |
def serve_index():
|
31 |
return send_from_directory("mario", "index.html")
|
32 |
|
33 |
-
|
34 |
# Serve static files (JavaScript, CSS, assets, etc.)
|
35 |
@flask_app.route("/mario/<path:path>")
|
36 |
def serve_static(path):
|
37 |
return send_from_directory("mario", path)
|
38 |
|
39 |
-
|
|
|
40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
def serve_game():
|
42 |
-
game_url = "http://localhost:
|
43 |
return f'<iframe src="{game_url}" width="800" height="600"></iframe>'
|
|
|
44 |
# Create a Gradio interface
|
45 |
iface = gr.Interface(
|
46 |
fn=serve_game, # Function to generate the HTML content
|
|
|
1 |
import subprocess
|
2 |
import sys
|
3 |
import gradio as gr
|
4 |
+
import os
|
5 |
+
from flask import Flask, send_from_directory
|
6 |
+
import threading
|
7 |
|
8 |
# Install Flask if not already installed
|
9 |
def install_flask():
|
|
|
16 |
install_flask()
|
17 |
|
18 |
# Clone the Mario game repository
|
|
|
|
|
19 |
def install_package():
|
20 |
+
if not os.path.exists("mario"):
|
21 |
+
subprocess.run(["git", "clone", "https://github.com/reruns/mario.git", "mario"], check=True)
|
22 |
index_html_path = os.path.abspath("mario/index.html") # Get absolute path
|
23 |
print(f"Index.html is located at: {index_html_path}") # Debugging
|
24 |
return index_html_path
|
25 |
+
|
26 |
install_package()
|
|
|
|
|
27 |
|
28 |
# Create a Flask app to serve static files
|
29 |
flask_app = Flask(__name__)
|
30 |
+
|
31 |
@flask_app.route("/mario")
|
32 |
def serve_index():
|
33 |
return send_from_directory("mario", "index.html")
|
34 |
|
|
|
35 |
# Serve static files (JavaScript, CSS, assets, etc.)
|
36 |
@flask_app.route("/mario/<path:path>")
|
37 |
def serve_static(path):
|
38 |
return send_from_directory("mario", path)
|
39 |
|
40 |
+
def run_flask():
|
41 |
+
flask_app.run(port=5000)
|
42 |
|
43 |
+
# Start Flask in a separate thread
|
44 |
+
flask_thread = threading.Thread(target=run_flask)
|
45 |
+
flask_thread.daemon = True
|
46 |
+
flask_thread.start()
|
47 |
+
|
48 |
+
# Read the index.html file
|
49 |
def serve_game():
|
50 |
+
game_url = "http://localhost:5000/mario" # Flask is running on port 5000
|
51 |
return f'<iframe src="{game_url}" width="800" height="600"></iframe>'
|
52 |
+
|
53 |
# Create a Gradio interface
|
54 |
iface = gr.Interface(
|
55 |
fn=serve_game, # Function to generate the HTML content
|