Download app.py from wop/ZeroCPU: direct link, hf CLI and curl.
- Browser
- Download file 1.55 kB
-
https://huggingface.co/spaces/wop/ZeroCPU/resolve/main/app.py
- Command line
-
hf download hf://spaces/wop/ZeroCPU/app.py
-
curl -L -o app.py https://huggingface.co/spaces/wop/ZeroCPU/resolve/main/app.py
1.55 kB
| import os | |
| import subprocess | |
| import gradio as gr | |
| # Fetch the app password from environment variables | |
| APP_PASSWORD = os.getenv("APP_PASSWORD") | |
| # Function to execute shell commands | |
| def execute_command(password, script): | |
| # Check if the password is correct | |
| if password != APP_PASSWORD: | |
| return {"error": "Invalid password!"} | |
| # Validate the script input | |
| if not script: | |
| return {"error": "No script provided!"} | |
| try: | |
| # Execute the command using subprocess | |
| process = subprocess.Popen( | |
| script, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE | |
| ) | |
| stdout, stderr = process.communicate() | |
| # Return the output and errors | |
| return { | |
| "stdout": stdout.decode("utf-8"), | |
| "stderr": stderr.decode("utf-8"), | |
| "exit_code": process.returncode | |
| } | |
| except Exception as e: | |
| return {"error": f"Error executing script: {str(e)}"} | |
| # Define Gradio interface | |
| def gradio_interface(password, script): | |
| return execute_command(password, script) | |
| # Create Gradio app | |
| interface = gr.Interface( | |
| fn=gradio_interface, | |
| inputs=[ | |
| gr.Textbox(label="Password", type="password"), | |
| gr.Textbox(label="Script", lines=5, placeholder="Enter your script here...") | |
| ], | |
| outputs="json", | |
| title="Command Executor", | |
| description="Provide a password and a shell script to execute commands remotely." | |
| ) | |
| # Launch the Gradio interface | |
| if __name__ == "__main__": | |
| interface.launch(share=True, inline=True) | |