Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import os | |
| import requests | |
| # Hugging Face API settings | |
| HF_USERNAME = "yourusername" # Change to your HF username | |
| HF_REPO_ID = f"{HF_USERNAME}/rbo-games" | |
| HF_BASE_URL = f"https://huggingface.co/datasets/{HF_REPO_ID}/resolve/main/" | |
| # List of available RBO games stored in Hugging Face | |
| GAMES = { | |
| "Super RBO Adventure": f"{HF_BASE_URL}super_rbo_adventure.rbo", | |
| "RBO Racing": f"{HF_BASE_URL}rbo_racing.rbo", | |
| "RBO Battle": f"{HF_BASE_URL}rbo_battle.rbo" | |
| } | |
| DOWNLOAD_FOLDER = "downloads" | |
| os.makedirs(DOWNLOAD_FOLDER, exist_ok=True) | |
| # Function to search for games | |
| def search_rbo_game(query): | |
| results = [game for game in GAMES.keys() if query.lower() in game.lower()] | |
| return results if results else ["No games found."] | |
| # Function to download the RBO game from Hugging Face | |
| def download_rbo(game_name): | |
| if game_name not in GAMES: | |
| return "Game not found." | |
| url = GAMES[game_name] | |
| file_path = os.path.join(DOWNLOAD_FOLDER, f"{game_name}.rbo") | |
| # Download the file from Hugging Face | |
| response = requests.get(url, stream=True) | |
| if response.status_code == 200: | |
| with open(file_path, "wb") as f: | |
| for chunk in response.iter_content(chunk_size=1024): | |
| f.write(chunk) | |
| return f"Downloaded: {file_path}" | |
| else: | |
| return "Failed to download the game." | |
| # Gradio UI | |
| with gr.Blocks() as app: | |
| gr.Markdown("# 🎮 RBO Player - Search & Play RBO Games") | |
| # Search Section | |
| with gr.Row(): | |
| search_box = gr.Textbox(placeholder="Search for an RBO game...") | |
| search_results = gr.Dropdown(choices=[], label="Select Game") | |
| search_button = gr.Button("Search") | |
| search_button.click(search_rbo_game, inputs=search_box, outputs=search_results) | |
| # Download Section | |
| download_button = gr.Button("Download & Play") | |
| download_status = gr.Textbox(label="Status") | |
| download_button.click(download_rbo, inputs=search_results, outputs=download_status) | |
| # Launch app | |
| if __name__ == "__main__": | |
| app.launch(server_name="0.0.0.0", server_port=7860) | |