Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Flask, send_from_directory
|
2 |
+
import gradio as gr
|
3 |
+
import threading
|
4 |
+
|
5 |
+
# Create a Flask app to serve static files
|
6 |
+
flask_app = Flask(__name__)
|
7 |
+
|
8 |
+
# Serve the Mario game files
|
9 |
+
@flask_app.route("/mario")
|
10 |
+
def serve_index():
|
11 |
+
return send_from_directory("/app/mario", "index.html")
|
12 |
+
|
13 |
+
# Serve static files (JavaScript, CSS, assets, etc.)
|
14 |
+
@flask_app.route("/mario/<path:path>")
|
15 |
+
def serve_static(path):
|
16 |
+
return send_from_directory("/app/mario", path)
|
17 |
+
|
18 |
+
# Run Flask in a separate thread
|
19 |
+
def run_flask():
|
20 |
+
flask_app.run(host="0.0.0.0", port=5000)
|
21 |
+
|
22 |
+
flask_thread = threading.Thread(target=run_flask)
|
23 |
+
flask_thread.daemon = True
|
24 |
+
flask_thread.start()
|
25 |
+
|
26 |
+
# Gradio interface to embed the game
|
27 |
+
def serve_game():
|
28 |
+
game_url = "http://localhost:5000/mario" # Flask is running on port 5000
|
29 |
+
return f'<iframe src="{game_url}" width="800" height="600"></iframe>'
|
30 |
+
|
31 |
+
# Create a Gradio interface
|
32 |
+
iface = gr.Interface(
|
33 |
+
fn=serve_game, # Function to generate the HTML content
|
34 |
+
inputs=None, # No inputs needed
|
35 |
+
outputs=gr.HTML(), # Output is HTML content
|
36 |
+
live=True, # Keep the interface live
|
37 |
+
title="Mario HTML Game",
|
38 |
+
description="Play the Mario HTML game embedded in Gradio!"
|
39 |
+
)
|
40 |
+
|
41 |
+
# Launch the Gradio app
|
42 |
+
iface.launch(server_name="0.0.0.0", server_port=7860)
|