File size: 2,008 Bytes
deb8fc1
63ce4a0
deb8fc1
fe39c08
 
 
63ce4a0
 
 
 
 
 
20134da
63ce4a0
20134da
63ce4a0
 
 
deb8fc1
57989d0
deb8fc1
fe39c08
 
965a7ed
 
 
fe39c08
deb8fc1
 
57989d0
 
fe39c08
51bd00e
 
 
 
57989d0
 
 
 
 
fe39c08
 
e7efbe3
fe39c08
 
 
 
 
 
deb8fc1
fe39c08
9d0e62f
fe39c08
deb8fc1
 
57989d0
deb8fc1
 
 
 
 
 
 
 
57989d0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import subprocess
import sys
import gradio as gr
import os
from flask import Flask, send_from_directory
import threading

# Install Flask if not already installed
def install_flask():
    try:
        import flask
    except ImportError:
        print("Flask not found. Installing Flask...")
        subprocess.run([sys.executable, "-m", "pip", "install", "flask"], check=True)
        import flask  # Try importing again after installation

# Install Flask on startup
install_flask()

# Clone the Mario game repository
def install_package():
    if not os.path.exists("mario"):
        subprocess.run(["git", "clone", "https://github.com/reruns/mario.git", "mario"], check=True)
    index_html_path = os.path.abspath("mario/index.html")  # Get absolute path
    print(f"Index.html is located at: {index_html_path}")  # Debugging
    return index_html_path

install_package()

# Create a Flask app to serve static files
flask_app = Flask(__name__)

@flask_app.route("/mario")
def serve_index():
    return send_from_directory("mario", "index.html")

# Serve static files (JavaScript, CSS, assets, etc.)
@flask_app.route("/mario/<path:path>")
def serve_static(path):
    return send_from_directory("mario", path)

def run_flask():
    flask_app.run(port=5000)

# Start Flask in a separate thread
flask_thread = threading.Thread(target=run_flask)
flask_thread.daemon = True
flask_thread.start()

# Read the index.html file
def serve_game():
    game_url = "http://localhost:5000/mario"  # Flask is running on port 5000
    return f'<iframe src="{game_url}" width="800" height="600"></iframe>'

# Create a Gradio interface
iface = gr.Interface(
    fn=serve_game,  # Function to generate the HTML content
    inputs=None,    # No inputs needed
    outputs=gr.HTML(),  # Output is HTML content
    live=True,      # Keep the interface live
    title="Mario HTML Game",
    description="Play the Mario HTML game embedded in Gradio!"
)

# Launch the Gradio app
iface.launch(server_name="0.0.0.0", server_port=7860)