Update app.py
Browse files
app.py
CHANGED
|
@@ -1,55 +1,46 @@
|
|
| 1 |
import os
|
|
|
|
| 2 |
import time
|
| 3 |
|
| 4 |
-
# Display set karna
|
| 5 |
os.environ["DISPLAY"] = ":99"
|
| 6 |
|
| 7 |
import base64
|
| 8 |
from flask import Flask, request, jsonify
|
| 9 |
from flask_cors import CORS
|
| 10 |
import pyautogui
|
| 11 |
-
|
| 12 |
-
from PIL import Image
|
| 13 |
-
import io
|
| 14 |
|
| 15 |
app = Flask(__name__)
|
| 16 |
CORS(app)
|
| 17 |
|
| 18 |
SCREEN_WIDTH = 1024
|
| 19 |
SCREEN_HEIGHT = 768
|
| 20 |
-
|
| 21 |
-
# Fail-safes disable
|
| 22 |
pyautogui.FAILSAFE = False
|
| 23 |
|
| 24 |
-
# MSS (Fast Screenshot) Setup
|
| 25 |
-
sct = mss.mss()
|
| 26 |
-
# Monitor 1 ko pakdo
|
| 27 |
-
monitor = sct.monitors[1]
|
| 28 |
-
|
| 29 |
@app.route('/')
|
| 30 |
def home():
|
| 31 |
-
return "Cloud PC
|
| 32 |
|
| 33 |
@app.route('/snapshot', methods=['GET'])
|
| 34 |
def get_snapshot():
|
| 35 |
try:
|
| 36 |
-
#
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
# Raw bytes ko Image mein convert karo
|
| 40 |
-
img = Image.frombytes("RGB", sct_img.size, sct_img.bgra, "raw", "BGRX")
|
| 41 |
|
| 42 |
-
#
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
buffer = io.BytesIO()
|
| 46 |
-
img.save(buffer, format="JPEG", quality=60)
|
| 47 |
-
b64 = base64.b64encode(buffer.getvalue()).decode('utf-8')
|
| 48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
return jsonify({"screenshot": b64})
|
|
|
|
| 50 |
except Exception as e:
|
| 51 |
-
|
| 52 |
-
|
| 53 |
return jsonify({"error": str(e)}), 500
|
| 54 |
|
| 55 |
@app.route('/interact', methods=['POST'])
|
|
@@ -75,16 +66,14 @@ def interact():
|
|
| 75 |
pyautogui.scroll(-5)
|
| 76 |
|
| 77 |
elif action == 'open_terminal':
|
| 78 |
-
|
| 79 |
|
| 80 |
elif action == 'open_browser':
|
| 81 |
-
|
| 82 |
|
| 83 |
return jsonify({"status": "ok"})
|
| 84 |
except Exception as e:
|
| 85 |
-
print(f"INTERACT ERROR: {e}")
|
| 86 |
return jsonify({"error": str(e)}), 500
|
| 87 |
|
| 88 |
if __name__ == '__main__':
|
| 89 |
-
# Threaded=False kabhi kabhi crash rokta hai
|
| 90 |
app.run(host='0.0.0.0', port=7860, threaded=True)
|
|
|
|
| 1 |
import os
|
| 2 |
+
import subprocess
|
| 3 |
import time
|
| 4 |
|
| 5 |
+
# Display set karna
|
| 6 |
os.environ["DISPLAY"] = ":99"
|
| 7 |
|
| 8 |
import base64
|
| 9 |
from flask import Flask, request, jsonify
|
| 10 |
from flask_cors import CORS
|
| 11 |
import pyautogui
|
| 12 |
+
# mss hata diya hai, hum direct system command use karenge (failsafe)
|
|
|
|
|
|
|
| 13 |
|
| 14 |
app = Flask(__name__)
|
| 15 |
CORS(app)
|
| 16 |
|
| 17 |
SCREEN_WIDTH = 1024
|
| 18 |
SCREEN_HEIGHT = 768
|
|
|
|
|
|
|
| 19 |
pyautogui.FAILSAFE = False
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
@app.route('/')
|
| 22 |
def home():
|
| 23 |
+
return "Botisbot Cloud PC (Fluxbox Edition) Ready!"
|
| 24 |
|
| 25 |
@app.route('/snapshot', methods=['GET'])
|
| 26 |
def get_snapshot():
|
| 27 |
try:
|
| 28 |
+
# METHOD: Direct System Command (Sabse reliable method)
|
| 29 |
+
# Hum 'scrot' use karke image temp file mein save karenge aur fir read karenge
|
| 30 |
+
filename = "/tmp/screen.jpg"
|
|
|
|
|
|
|
| 31 |
|
| 32 |
+
# Scrot command: -z (silent), -o (overwrite), -q 50 (quality 50%)
|
| 33 |
+
subprocess.run(["scrot", "-z", "-o", "-q", "50", filename], check=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
+
# Image read karo
|
| 36 |
+
with open(filename, "rb") as image_file:
|
| 37 |
+
b64 = base64.b64encode(image_file.read()).decode('utf-8')
|
| 38 |
+
|
| 39 |
return jsonify({"screenshot": b64})
|
| 40 |
+
|
| 41 |
except Exception as e:
|
| 42 |
+
print(f"Snapshot Error: {e}")
|
| 43 |
+
# Agar error aaye to user ko batao
|
| 44 |
return jsonify({"error": str(e)}), 500
|
| 45 |
|
| 46 |
@app.route('/interact', methods=['POST'])
|
|
|
|
| 66 |
pyautogui.scroll(-5)
|
| 67 |
|
| 68 |
elif action == 'open_terminal':
|
| 69 |
+
subprocess.Popen(["xterm", "&"])
|
| 70 |
|
| 71 |
elif action == 'open_browser':
|
| 72 |
+
subprocess.Popen(["chromium-browser", "--no-sandbox"])
|
| 73 |
|
| 74 |
return jsonify({"status": "ok"})
|
| 75 |
except Exception as e:
|
|
|
|
| 76 |
return jsonify({"error": str(e)}), 500
|
| 77 |
|
| 78 |
if __name__ == '__main__':
|
|
|
|
| 79 |
app.run(host='0.0.0.0', port=7860, threaded=True)
|