Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,7 +4,7 @@ import zipfile
|
|
| 4 |
|
| 5 |
# Define paths
|
| 6 |
ZIP_FILE = "nes.zip"
|
| 7 |
-
EXTRACTED_FOLDER = "
|
| 8 |
|
| 9 |
# Ensure extraction directory exists
|
| 10 |
os.makedirs(EXTRACTED_FOLDER, exist_ok=True)
|
|
@@ -16,9 +16,10 @@ def extract_roms():
|
|
| 16 |
for file in zip_ref.namelist():
|
| 17 |
if not file.startswith("__MACOSX/"):
|
| 18 |
zip_ref.extract(file, EXTRACTED_FOLDER)
|
|
|
|
|
|
|
| 19 |
if file.endswith(".zip"):
|
| 20 |
-
|
| 21 |
-
extract_nested_zip(nested_zip_path)
|
| 22 |
else:
|
| 23 |
print("Error: `nes.zip` is missing. Upload it to the root directory.")
|
| 24 |
|
|
@@ -29,6 +30,7 @@ def extract_nested_zip(nested_zip_path):
|
|
| 29 |
os.makedirs(nested_folder, exist_ok=True)
|
| 30 |
nested_zip.extractall(nested_folder)
|
| 31 |
os.remove(nested_zip_path)
|
|
|
|
| 32 |
|
| 33 |
# Ensure ROMs are extracted on startup
|
| 34 |
extract_roms()
|
|
@@ -36,8 +38,12 @@ extract_roms()
|
|
| 36 |
# Function to list available ROMs
|
| 37 |
def list_roms():
|
| 38 |
if not os.path.exists(EXTRACTED_FOLDER):
|
|
|
|
| 39 |
return []
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
# Generate HTML content with links to the ROMs
|
| 43 |
def generate_html():
|
|
@@ -57,7 +63,7 @@ def generate_html():
|
|
| 57 |
|
| 58 |
if rom_files:
|
| 59 |
for rom_name in rom_files:
|
| 60 |
-
rom_url = f"
|
| 61 |
html_content += f'<li><a href="play.html?rom={rom_url}">{rom_name}</a></li>'
|
| 62 |
else:
|
| 63 |
html_content += "<li>No ROMs available</li>"
|
|
@@ -69,7 +75,6 @@ def generate_html():
|
|
| 69 |
"""
|
| 70 |
return html_content
|
| 71 |
|
| 72 |
-
|
| 73 |
# Gradio App
|
| 74 |
def gradio_app():
|
| 75 |
with gr.Blocks() as app:
|
|
@@ -80,8 +85,9 @@ def gradio_app():
|
|
| 80 |
|
| 81 |
show_html_button.click(generate_html, outputs=html_output)
|
| 82 |
|
| 83 |
-
app.launch(server_name="0.0.0.0", server_port=7860)
|
| 84 |
|
| 85 |
# Run Gradio app
|
| 86 |
gradio_app()
|
| 87 |
|
|
|
|
|
|
| 4 |
|
| 5 |
# Define paths
|
| 6 |
ZIP_FILE = "nes.zip"
|
| 7 |
+
EXTRACTED_FOLDER = "nes" # Match directory for serving
|
| 8 |
|
| 9 |
# Ensure extraction directory exists
|
| 10 |
os.makedirs(EXTRACTED_FOLDER, exist_ok=True)
|
|
|
|
| 16 |
for file in zip_ref.namelist():
|
| 17 |
if not file.startswith("__MACOSX/"):
|
| 18 |
zip_ref.extract(file, EXTRACTED_FOLDER)
|
| 19 |
+
extracted_path = os.path.join(EXTRACTED_FOLDER, file)
|
| 20 |
+
print(f"Extracted: {extracted_path}") # Debug output
|
| 21 |
if file.endswith(".zip"):
|
| 22 |
+
extract_nested_zip(extracted_path)
|
|
|
|
| 23 |
else:
|
| 24 |
print("Error: `nes.zip` is missing. Upload it to the root directory.")
|
| 25 |
|
|
|
|
| 30 |
os.makedirs(nested_folder, exist_ok=True)
|
| 31 |
nested_zip.extractall(nested_folder)
|
| 32 |
os.remove(nested_zip_path)
|
| 33 |
+
print(f"Extracted nested zip: {nested_zip_path}")
|
| 34 |
|
| 35 |
# Ensure ROMs are extracted on startup
|
| 36 |
extract_roms()
|
|
|
|
| 38 |
# Function to list available ROMs
|
| 39 |
def list_roms():
|
| 40 |
if not os.path.exists(EXTRACTED_FOLDER):
|
| 41 |
+
print("ROM folder missing.")
|
| 42 |
return []
|
| 43 |
+
|
| 44 |
+
roms = [f for f in os.listdir(EXTRACTED_FOLDER) if f.endswith(".nes")]
|
| 45 |
+
print("Found ROMs:", roms) # Debugging output
|
| 46 |
+
return roms
|
| 47 |
|
| 48 |
# Generate HTML content with links to the ROMs
|
| 49 |
def generate_html():
|
|
|
|
| 63 |
|
| 64 |
if rom_files:
|
| 65 |
for rom_name in rom_files:
|
| 66 |
+
rom_url = f"/file/{EXTRACTED_FOLDER}/{rom_name}" # Adjust for Gradio file serving
|
| 67 |
html_content += f'<li><a href="play.html?rom={rom_url}">{rom_name}</a></li>'
|
| 68 |
else:
|
| 69 |
html_content += "<li>No ROMs available</li>"
|
|
|
|
| 75 |
"""
|
| 76 |
return html_content
|
| 77 |
|
|
|
|
| 78 |
# Gradio App
|
| 79 |
def gradio_app():
|
| 80 |
with gr.Blocks() as app:
|
|
|
|
| 85 |
|
| 86 |
show_html_button.click(generate_html, outputs=html_output)
|
| 87 |
|
| 88 |
+
app.launch(server_name="0.0.0.0", server_port=7860, share=True)
|
| 89 |
|
| 90 |
# Run Gradio app
|
| 91 |
gradio_app()
|
| 92 |
|
| 93 |
+
|