Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ import gradio as gr
|
|
| 2 |
import os
|
| 3 |
import zipfile
|
| 4 |
from pathlib import Path
|
|
|
|
| 5 |
|
| 6 |
# Define paths
|
| 7 |
ZIP_FILE = "nes.zip"
|
|
@@ -53,33 +54,29 @@ def list_roms():
|
|
| 53 |
print("Found ROMs:", roms) # Debugging output
|
| 54 |
return [str(rom.relative_to(EXTRACTED_FOLDER)) for rom in roms]
|
| 55 |
|
| 56 |
-
#
|
| 57 |
-
def
|
| 58 |
-
|
| 59 |
-
|
|
|
|
|
|
|
| 60 |
<html>
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
else:
|
| 78 |
-
html_content += "<li>No ROMs available</li>"
|
| 79 |
-
|
| 80 |
-
html_content += """
|
| 81 |
-
</ul>
|
| 82 |
-
</body>
|
| 83 |
</html>
|
| 84 |
"""
|
| 85 |
return html_content
|
|
@@ -89,10 +86,16 @@ def gradio_app():
|
|
| 89 |
with gr.Blocks() as app:
|
| 90 |
gr.Markdown("# 🎮 Retro ROM File Server")
|
| 91 |
|
| 92 |
-
|
| 93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
-
|
|
|
|
| 96 |
|
| 97 |
app.launch(server_name="0.0.0.0", server_port=7860, share=True)
|
| 98 |
|
|
@@ -102,3 +105,4 @@ gradio_app()
|
|
| 102 |
|
| 103 |
|
| 104 |
|
|
|
|
|
|
| 2 |
import os
|
| 3 |
import zipfile
|
| 4 |
from pathlib import Path
|
| 5 |
+
import urllib.parse
|
| 6 |
|
| 7 |
# Define paths
|
| 8 |
ZIP_FILE = "nes.zip"
|
|
|
|
| 54 |
print("Found ROMs:", roms) # Debugging output
|
| 55 |
return [str(rom.relative_to(EXTRACTED_FOLDER)) for rom in roms]
|
| 56 |
|
| 57 |
+
# Function to generate HTML for playing the selected ROM
|
| 58 |
+
def generate_rom_page(rom_name):
|
| 59 |
+
rom_path = os.path.join(EXTRACTED_FOLDER, rom_name)
|
| 60 |
+
rom_url = urllib.parse.quote(rom_path) # Ensure correct URL encoding
|
| 61 |
+
|
| 62 |
+
html_content = f"""
|
| 63 |
<html>
|
| 64 |
+
<head>
|
| 65 |
+
<div style='width:640px;height:480px;max-width:100%'>
|
| 66 |
+
<div id='game'></div>
|
| 67 |
+
</div>
|
| 68 |
+
|
| 69 |
+
<script>
|
| 70 |
+
EJS_player = "#game";
|
| 71 |
+
EJS_core = "nes";
|
| 72 |
+
EJS_color = "#0064ff";
|
| 73 |
+
EJS_pathtodata = "https://cdn.emulatorjs.org/stable/data/";
|
| 74 |
+
EJS_gameUrl = "https://sudo-soldier-nes.hf.space/RETRO/{rom_url}";
|
| 75 |
+
</script>
|
| 76 |
+
<script src="https://cdn.emulatorjs.org/stable/data/loader.js"></script>
|
| 77 |
+
</head>
|
| 78 |
+
<body>
|
| 79 |
+
</body>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
</html>
|
| 81 |
"""
|
| 82 |
return html_content
|
|
|
|
| 86 |
with gr.Blocks() as app:
|
| 87 |
gr.Markdown("# 🎮 Retro ROM File Server")
|
| 88 |
|
| 89 |
+
# List available ROMs and create a button for each
|
| 90 |
+
rom_files = list_roms()
|
| 91 |
+
|
| 92 |
+
if rom_files:
|
| 93 |
+
for rom_name in rom_files:
|
| 94 |
+
# Create a button for each ROM
|
| 95 |
+
gr.Button(rom_name).click(generate_rom_page, inputs=gr.State(rom_name), outputs=gr.HTML())
|
| 96 |
|
| 97 |
+
# Display the ROM page
|
| 98 |
+
gr.HTML(label="ROM Emulator").style(height=500)
|
| 99 |
|
| 100 |
app.launch(server_name="0.0.0.0", server_port=7860, share=True)
|
| 101 |
|
|
|
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
+
|