ayush-thakur02 commited on
Commit
e8f127f
·
verified ·
1 Parent(s): 28f2de7

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -0
app.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import subprocess
3
+ import threading
4
+ import time
5
+
6
+ # Define the URL and interval
7
+ url = 'https://baseline-btn5.onrender.com/'
8
+ interval = 13 * 60 # 13 minutes in seconds
9
+ subprocess_duration = 60 # Duration to run the subprocess in seconds (e.g., 60 seconds)
10
+
11
+ # Variables for subprocess and count
12
+ count = 0
13
+ subprocess_process = None
14
+
15
+ def open_website():
16
+ global subprocess_process, count
17
+ count += 1
18
+
19
+ if subprocess_process:
20
+ subprocess_process.terminate() # Terminate the previous subprocess if it exists
21
+
22
+ # Start a new subprocess to open the website
23
+ subprocess_process = subprocess.Popen(["python", "-c", f"import webbrowser; webbrowser.open('{url}')"])
24
+ # print(f"Website {url} opened. Count: {count}")
25
+
26
+ # Wait for the subprocess duration and then terminate it
27
+ time.sleep(subprocess_duration)
28
+ if subprocess_process:
29
+ subprocess_process.terminate() # Ensure subprocess is terminated after its run time
30
+ subprocess_process = None
31
+
32
+ def get_count():
33
+ return count
34
+
35
+ def background_task():
36
+ while True:
37
+ open_website()
38
+ time.sleep(interval) # Wait for the specified interval before opening the website again
39
+
40
+ # Start the background thread to manage website opening and subprocess termination
41
+ threading.Thread(target=background_task, daemon=True).start()
42
+
43
+ # Define the Gradio interface
44
+ def interface_function():
45
+ return f"Website opened count: {get_count()}"
46
+
47
+ iface = gr.Interface(fn=interface_function, inputs=[], outputs="text")
48
+
49
+ if __name__ == "__main__":
50
+ iface.launch(debug=True)