Gregniuki commited on
Commit
d9c1366
·
verified ·
1 Parent(s): ff8a585

Update app.py

Browse files

import subprocess
import gradio as gr

def install_package():
# Clone the Mario game repository (if not already cloned)
subprocess.run(["git", "clone", "https://github.com/reruns/mario.git", "mario"], check=True)

# Install the game files on startup
install_package()

# Define a function to serve the game
def serve_game():
# Read the index.html file from the cloned repository
with open("mario/index.html", "r") as file:
html_content = file.read()
return html_content

# Create a Gradio interface
iface = gr.Interface(
fn=serve_game, # Use the 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()

Files changed (1) hide show
  1. app.py +0 -29
app.py CHANGED
@@ -1,29 +0,0 @@
1
- import subprocess
2
- import gradio as gr
3
-
4
- def install_package():
5
- # Install the game files (optional, if you want to clone the repo programmatically)
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 the Gradio interface
12
- def serve_game():
13
- # Read the index.html file
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,
21
- inputs=None,
22
- outputs=gr.HTML(),
23
- live=True, # Keep the interface live to serve the game
24
- title="Mario HTML Game",
25
- description="Play the Mario HTML game embedded in Gradio!"
26
- )
27
-
28
- # Launch the Gradio app
29
- iface.launch()