Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import webbrowser
|
2 |
+
import time
|
3 |
+
import random
|
4 |
+
import pyautogui
|
5 |
+
import threading
|
6 |
+
import gradio as gr
|
7 |
+
|
8 |
+
# Global flag for controlling the process
|
9 |
+
running = False
|
10 |
+
|
11 |
+
# Function to start refreshing
|
12 |
+
def start_refreshing(url):
|
13 |
+
global running
|
14 |
+
running = True
|
15 |
+
webbrowser.open(url) # Open the URL initially
|
16 |
+
time.sleep(random.randint(5, 10))
|
17 |
+
|
18 |
+
while running:
|
19 |
+
pyautogui.hotkey("ctrl", "f5") # Refresh the tab
|
20 |
+
time.sleep(random.randint(5, 10)) # Wait before refreshing again
|
21 |
+
|
22 |
+
return "Refreshing started!"
|
23 |
+
|
24 |
+
# Function to stop refreshing
|
25 |
+
def stop_refreshing():
|
26 |
+
global running
|
27 |
+
running = False
|
28 |
+
return "Refreshing stopped!"
|
29 |
+
|
30 |
+
# Function to run the process in a separate thread
|
31 |
+
def run_refreshing(url):
|
32 |
+
thread = threading.Thread(target=start_refreshing, args=(url,))
|
33 |
+
thread.start()
|
34 |
+
return "Process started!"
|
35 |
+
|
36 |
+
# Gradio UI
|
37 |
+
with gr.Blocks() as app:
|
38 |
+
gr.Markdown("### Auto Refresh YouTube Tab with Random Intervals")
|
39 |
+
|
40 |
+
url_input = gr.Textbox(value="https://www.youtube.com/watch?v=N8X_6GPPTzc", label="Enter URL")
|
41 |
+
|
42 |
+
start_button = gr.Button("Start Refreshing")
|
43 |
+
stop_button = gr.Button("Stop Refreshing")
|
44 |
+
|
45 |
+
output = gr.Textbox(label="Status", interactive=False)
|
46 |
+
|
47 |
+
start_button.click(run_refreshing, inputs=[url_input], outputs=[output])
|
48 |
+
stop_button.click(stop_refreshing, outputs=[output])
|
49 |
+
|
50 |
+
app.launch()
|