Percy3822 commited on
Commit
b80e30a
·
verified ·
1 Parent(s): 206251c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -21
app.py CHANGED
@@ -1,28 +1,17 @@
1
  import gradio as gr
2
  import mss
 
3
  import numpy as np
4
- import PIL.Image
5
- import threading
6
- import time
7
 
8
- latest_frame = None
9
-
10
- def capture_loop():
11
- global latest_frame
12
  with mss.mss() as sct:
13
- monitor = sct.monitors[1]
14
- while True:
15
- screenshot = sct.grab(monitor)
16
- img = PIL.Image.frombytes("RGB", screenshot.size, screenshot.rgb)
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
- # Start the capture loop in the background
24
- threading.Thread(target=capture_loop, daemon=True).start()
25
 
26
- # UI
27
- demo = gr.Interface(fn=get_latest_frame, inputs=[], outputs="image", live=True)
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()