Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
import requests
|
| 4 |
+
|
| 5 |
+
# Hugging Face API settings
|
| 6 |
+
HF_USERNAME = "yourusername" # Change to your HF username
|
| 7 |
+
HF_REPO_ID = f"{HF_USERNAME}/rbo-games"
|
| 8 |
+
HF_BASE_URL = f"https://huggingface.co/datasets/{HF_REPO_ID}/resolve/main/"
|
| 9 |
+
|
| 10 |
+
# List of available RBO games stored in Hugging Face
|
| 11 |
+
GAMES = {
|
| 12 |
+
"Super RBO Adventure": f"{HF_BASE_URL}super_rbo_adventure.rbo",
|
| 13 |
+
"RBO Racing": f"{HF_BASE_URL}rbo_racing.rbo",
|
| 14 |
+
"RBO Battle": f"{HF_BASE_URL}rbo_battle.rbo"
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
DOWNLOAD_FOLDER = "downloads"
|
| 18 |
+
os.makedirs(DOWNLOAD_FOLDER, exist_ok=True)
|
| 19 |
+
|
| 20 |
+
# Function to search for games
|
| 21 |
+
def search_rbo_game(query):
|
| 22 |
+
results = [game for game in GAMES.keys() if query.lower() in game.lower()]
|
| 23 |
+
return results if results else ["No games found."]
|
| 24 |
+
|
| 25 |
+
# Function to download the RBO game from Hugging Face
|
| 26 |
+
def download_rbo(game_name):
|
| 27 |
+
if game_name not in GAMES:
|
| 28 |
+
return "Game not found."
|
| 29 |
+
|
| 30 |
+
url = GAMES[game_name]
|
| 31 |
+
file_path = os.path.join(DOWNLOAD_FOLDER, f"{game_name}.rbo")
|
| 32 |
+
|
| 33 |
+
# Download the file from Hugging Face
|
| 34 |
+
response = requests.get(url, stream=True)
|
| 35 |
+
if response.status_code == 200:
|
| 36 |
+
with open(file_path, "wb") as f:
|
| 37 |
+
for chunk in response.iter_content(chunk_size=1024):
|
| 38 |
+
f.write(chunk)
|
| 39 |
+
return f"Downloaded: {file_path}"
|
| 40 |
+
else:
|
| 41 |
+
return "Failed to download the game."
|
| 42 |
+
|
| 43 |
+
# Gradio UI
|
| 44 |
+
with gr.Blocks() as app:
|
| 45 |
+
gr.Markdown("# 🎮 RBO Player - Search & Play RBO Games")
|
| 46 |
+
|
| 47 |
+
# Search Section
|
| 48 |
+
with gr.Row():
|
| 49 |
+
search_box = gr.Textbox(placeholder="Search for an RBO game...")
|
| 50 |
+
search_results = gr.Dropdown(choices=[], label="Select Game")
|
| 51 |
+
|
| 52 |
+
search_button = gr.Button("Search")
|
| 53 |
+
search_button.click(search_rbo_game, inputs=search_box, outputs=search_results)
|
| 54 |
+
|
| 55 |
+
# Download Section
|
| 56 |
+
download_button = gr.Button("Download & Play")
|
| 57 |
+
download_status = gr.Textbox(label="Status")
|
| 58 |
+
|
| 59 |
+
download_button.click(download_rbo, inputs=search_results, outputs=download_status)
|
| 60 |
+
|
| 61 |
+
# Launch app
|
| 62 |
+
if __name__ == "__main__":
|
| 63 |
+
app.launch(server_name="0.0.0.0", server_port=7860)
|