Gregniuki commited on
Commit
00ae707
·
verified ·
1 Parent(s): 5d3c1bc

Update app.py

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