Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,28 +1,17 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import mss
|
|
|
|
| 3 |
import numpy as np
|
| 4 |
-
import
|
| 5 |
-
import threading
|
| 6 |
-
import time
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
def capture_loop():
|
| 11 |
-
global latest_frame
|
| 12 |
with mss.mss() as sct:
|
| 13 |
-
monitor = sct.monitors[1]
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
latest_frame = img
|
| 18 |
-
time.sleep(0.2) # ~5 times per second
|
| 19 |
-
|
| 20 |
-
def get_latest_frame():
|
| 21 |
-
return latest_frame
|
| 22 |
|
| 23 |
-
|
| 24 |
-
threading.Thread(target=capture_loop, daemon=True).start()
|
| 25 |
|
| 26 |
-
|
| 27 |
-
demo
|
| 28 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import mss
|
| 3 |
+
from PIL import Image
|
| 4 |
import numpy as np
|
| 5 |
+
import io
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
def capture_screen():
|
|
|
|
|
|
|
|
|
|
| 8 |
with mss.mss() as sct:
|
| 9 |
+
monitor = sct.monitors[1] # full screen
|
| 10 |
+
screenshot = sct.grab(monitor)
|
| 11 |
+
img = Image.frombytes("RGB", screenshot.size, screenshot.rgb)
|
| 12 |
+
return img
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
demo = gr.Interface(fn=capture_screen, inputs=[], outputs="image")
|
|
|
|
| 15 |
|
| 16 |
+
if __name__ == "__main__":
|
| 17 |
+
demo.launch()
|
|
|