Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,9 @@
|
|
| 1 |
import os
|
| 2 |
import time
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
import base64
|
| 4 |
import threading
|
| 5 |
from flask import Flask, request, jsonify, send_file
|
|
@@ -12,42 +16,34 @@ import io
|
|
| 12 |
app = Flask(__name__)
|
| 13 |
CORS(app)
|
| 14 |
|
| 15 |
-
# --- DISPLAY SETUP ---
|
| 16 |
-
os.environ["DISPLAY"] = ":99"
|
| 17 |
SCREEN_WIDTH = 1024
|
| 18 |
SCREEN_HEIGHT = 768
|
| 19 |
|
| 20 |
-
#
|
| 21 |
pyautogui.FAILSAFE = False
|
| 22 |
-
pyautogui.PAUSE = 0.
|
| 23 |
|
| 24 |
-
# Screenshot Manager (MSS is faster than Scrot)
|
| 25 |
sct = mss.mss()
|
| 26 |
monitor = {"top": 0, "left": 0, "width": SCREEN_WIDTH, "height": SCREEN_HEIGHT}
|
| 27 |
|
| 28 |
-
# --- ROUTES ---
|
| 29 |
-
|
| 30 |
@app.route('/')
|
| 31 |
def home():
|
| 32 |
-
return "Cloud PC
|
| 33 |
|
| 34 |
@app.route('/snapshot', methods=['GET'])
|
| 35 |
def get_snapshot():
|
| 36 |
try:
|
| 37 |
-
# Capture full desktop
|
| 38 |
sct_img = sct.grab(monitor)
|
| 39 |
img = Image.frombytes("RGB", sct_img.size, sct_img.bgra, "raw", "BGRX")
|
|
|
|
| 40 |
|
| 41 |
-
# Resize for Mobile Speed (Width 400px is enough for control)
|
| 42 |
-
img.thumbnail((500, 500))
|
| 43 |
-
|
| 44 |
-
# Compress to JPEG
|
| 45 |
buffer = io.BytesIO()
|
| 46 |
-
img.save(buffer, format="JPEG", quality=
|
| 47 |
b64 = base64.b64encode(buffer.getvalue()).decode('utf-8')
|
| 48 |
|
| 49 |
return jsonify({"screenshot": b64})
|
| 50 |
except Exception as e:
|
|
|
|
| 51 |
return jsonify({"error": str(e)}), 500
|
| 52 |
|
| 53 |
@app.route('/interact', methods=['POST'])
|
|
@@ -57,44 +53,30 @@ def interact():
|
|
| 57 |
|
| 58 |
try:
|
| 59 |
if action == 'tap':
|
| 60 |
-
# Map mobile coordinates to PC resolution
|
| 61 |
x = int(data.get('x') * SCREEN_WIDTH)
|
| 62 |
y = int(data.get('y') * SCREEN_HEIGHT)
|
| 63 |
pyautogui.click(x, y)
|
| 64 |
|
| 65 |
elif action == 'type':
|
| 66 |
-
|
| 67 |
-
pyautogui.write(text)
|
| 68 |
|
| 69 |
elif action == 'key':
|
| 70 |
-
|
| 71 |
-
pyautogui.press(
|
|
|
|
| 72 |
|
| 73 |
elif action == 'scroll':
|
| 74 |
-
pyautogui.scroll(-5)
|
| 75 |
|
| 76 |
elif action == 'open_terminal':
|
| 77 |
-
|
| 78 |
-
pyautogui.hotkey('ctrl', 'alt', 't')
|
| 79 |
|
| 80 |
elif action == 'open_browser':
|
| 81 |
-
# Command to run chromium
|
| 82 |
os.system("chromium-browser --no-sandbox &")
|
| 83 |
|
| 84 |
return jsonify({"status": "ok"})
|
| 85 |
except Exception as e:
|
| 86 |
return jsonify({"error": str(e)}), 500
|
| 87 |
|
| 88 |
-
# --- FILE TRANSFER ---
|
| 89 |
-
# Agar aap Antigravity se App banate hain, to wo '/app/output.apk' mein save karein
|
| 90 |
-
@app.route('/download', methods=['GET'])
|
| 91 |
-
def download_app():
|
| 92 |
-
# Example path (Change logic later based on where Antigravity saves files)
|
| 93 |
-
file_path = "/app/output.apk"
|
| 94 |
-
if os.path.exists(file_path):
|
| 95 |
-
return send_file(file_path, as_attachment=True)
|
| 96 |
-
else:
|
| 97 |
-
return "File not found yet. Build the app first!", 404
|
| 98 |
-
|
| 99 |
if __name__ == '__main__':
|
| 100 |
app.run(host='0.0.0.0', port=7860, threaded=True)
|
|
|
|
| 1 |
import os
|
| 2 |
import time
|
| 3 |
+
|
| 4 |
+
# --- CRITICAL FIX: Set Display before importing PyAutoGUI ---
|
| 5 |
+
os.environ["DISPLAY"] = ":99"
|
| 6 |
+
|
| 7 |
import base64
|
| 8 |
import threading
|
| 9 |
from flask import Flask, request, jsonify, send_file
|
|
|
|
| 16 |
app = Flask(__name__)
|
| 17 |
CORS(app)
|
| 18 |
|
|
|
|
|
|
|
| 19 |
SCREEN_WIDTH = 1024
|
| 20 |
SCREEN_HEIGHT = 768
|
| 21 |
|
| 22 |
+
# PyAutoGUI Settings
|
| 23 |
pyautogui.FAILSAFE = False
|
| 24 |
+
pyautogui.PAUSE = 0.1
|
| 25 |
|
|
|
|
| 26 |
sct = mss.mss()
|
| 27 |
monitor = {"top": 0, "left": 0, "width": SCREEN_WIDTH, "height": SCREEN_HEIGHT}
|
| 28 |
|
|
|
|
|
|
|
| 29 |
@app.route('/')
|
| 30 |
def home():
|
| 31 |
+
return "Cloud PC Ready. Connect via HTML."
|
| 32 |
|
| 33 |
@app.route('/snapshot', methods=['GET'])
|
| 34 |
def get_snapshot():
|
| 35 |
try:
|
|
|
|
| 36 |
sct_img = sct.grab(monitor)
|
| 37 |
img = Image.frombytes("RGB", sct_img.size, sct_img.bgra, "raw", "BGRX")
|
| 38 |
+
img.thumbnail((600, 600)) # Resize for speed
|
| 39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
buffer = io.BytesIO()
|
| 41 |
+
img.save(buffer, format="JPEG", quality=50)
|
| 42 |
b64 = base64.b64encode(buffer.getvalue()).decode('utf-8')
|
| 43 |
|
| 44 |
return jsonify({"screenshot": b64})
|
| 45 |
except Exception as e:
|
| 46 |
+
print(f"Snapshot Error: {e}")
|
| 47 |
return jsonify({"error": str(e)}), 500
|
| 48 |
|
| 49 |
@app.route('/interact', methods=['POST'])
|
|
|
|
| 53 |
|
| 54 |
try:
|
| 55 |
if action == 'tap':
|
|
|
|
| 56 |
x = int(data.get('x') * SCREEN_WIDTH)
|
| 57 |
y = int(data.get('y') * SCREEN_HEIGHT)
|
| 58 |
pyautogui.click(x, y)
|
| 59 |
|
| 60 |
elif action == 'type':
|
| 61 |
+
pyautogui.write(data.get('text'))
|
|
|
|
| 62 |
|
| 63 |
elif action == 'key':
|
| 64 |
+
k = data.get('key').lower()
|
| 65 |
+
if k == 'enter': pyautogui.press('enter')
|
| 66 |
+
elif k == 'backspace': pyautogui.press('backspace')
|
| 67 |
|
| 68 |
elif action == 'scroll':
|
| 69 |
+
pyautogui.scroll(-5)
|
| 70 |
|
| 71 |
elif action == 'open_terminal':
|
| 72 |
+
os.system("xfce4-terminal &")
|
|
|
|
| 73 |
|
| 74 |
elif action == 'open_browser':
|
|
|
|
| 75 |
os.system("chromium-browser --no-sandbox &")
|
| 76 |
|
| 77 |
return jsonify({"status": "ok"})
|
| 78 |
except Exception as e:
|
| 79 |
return jsonify({"error": str(e)}), 500
|
| 80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
if __name__ == '__main__':
|
| 82 |
app.run(host='0.0.0.0', port=7860, threaded=True)
|