Akwbw commited on
Commit
841b576
·
verified ·
1 Parent(s): 7ca0788

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -14
app.py CHANGED
@@ -1,15 +1,13 @@
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
10
  from flask_cors import CORS
11
  import pyautogui
12
- import mss
13
  from PIL import Image
14
  import io
15
 
@@ -19,23 +17,22 @@ CORS(app)
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)
@@ -43,7 +40,9 @@ def get_snapshot():
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'])
 
1
  import os
2
  import time
3
 
4
+ # Display set karna zaroori hai
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
  from PIL import Image
12
  import io
13
 
 
17
  SCREEN_WIDTH = 1024
18
  SCREEN_HEIGHT = 768
19
 
20
+ # Fail-safes disable karo taake mouse corner mein jane se app band na ho
21
  pyautogui.FAILSAFE = False
 
 
 
 
22
 
23
  @app.route('/')
24
  def home():
25
+ return "Cloud PC is Running! Use HTML Client."
26
 
27
  @app.route('/snapshot', methods=['GET'])
28
  def get_snapshot():
29
  try:
30
+ # METHOD CHANGE: mss ki jagah pyautogui use kar rahe hain (More Stable)
31
+ # Yeh seedha screen capture karega
32
+ img = pyautogui.screenshot()
33
+
34
+ # Resize kar rahe hain taake mobile par tez chale
35
+ img.thumbnail((600, 600))
36
 
37
  buffer = io.BytesIO()
38
  img.save(buffer, format="JPEG", quality=50)
 
40
 
41
  return jsonify({"screenshot": b64})
42
  except Exception as e:
43
+ # Error console mein print hoga
44
+ print(f"ERROR: {e}")
45
+ # Agar error aye to client ko batao (Black screen ki jagah error dikhega)
46
  return jsonify({"error": str(e)}), 500
47
 
48
  @app.route('/interact', methods=['POST'])