Spaces:
Sleeping
Sleeping
Delete app.py
Browse files
app.py
DELETED
|
@@ -1,72 +0,0 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
import threading
|
| 3 |
-
import time
|
| 4 |
-
import schedule
|
| 5 |
-
import random
|
| 6 |
-
import datetime
|
| 7 |
-
from playwright.sync_api import sync_playwright
|
| 8 |
-
import os
|
| 9 |
-
|
| 10 |
-
URL = "https://streamer1-gvbgwaea2w2qmwgjey7ksg.streamlit.app/"
|
| 11 |
-
logs = ["🚀 System initialized. First run starting..."]
|
| 12 |
-
|
| 13 |
-
def add_log(message):
|
| 14 |
-
timestamp = datetime.datetime.now().strftime('%H:%M:%S')
|
| 15 |
-
log_entry = f"[{timestamp}] {message}"
|
| 16 |
-
print(log_entry)
|
| 17 |
-
logs.append(log_entry)
|
| 18 |
-
if len(logs) > 50: logs.pop(0)
|
| 19 |
-
|
| 20 |
-
def visit_and_scroll():
|
| 21 |
-
add_log(f"Starting keep-alive visit to: {URL}")
|
| 22 |
-
try:
|
| 23 |
-
with sync_playwright() as p:
|
| 24 |
-
# Re-enabling explicit user-agent and simplified launch
|
| 25 |
-
browser = p.chromium.launch(
|
| 26 |
-
headless=True,
|
| 27 |
-
args=['--no-sandbox', '--disable-dev-shm-usage', '--disable-gpu']
|
| 28 |
-
)
|
| 29 |
-
context = browser.new_context(
|
| 30 |
-
user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
|
| 31 |
-
)
|
| 32 |
-
page = context.new_page()
|
| 33 |
-
|
| 34 |
-
page.goto(URL, wait_until='networkidle', timeout=60000)
|
| 35 |
-
add_log("Page loaded. Waiting 10s for Streamlit setup...")
|
| 36 |
-
time.sleep(10)
|
| 37 |
-
|
| 38 |
-
for i in range(1, 6):
|
| 39 |
-
scroll_y = i * 800
|
| 40 |
-
page.evaluate(f"window.scrollTo(0, {scroll_y});")
|
| 41 |
-
add_log(f"Scrolled to {scroll_y}px...")
|
| 42 |
-
time.sleep(random.uniform(1.5, 3.0))
|
| 43 |
-
|
| 44 |
-
page.evaluate("window.scrollTo(0, 0);")
|
| 45 |
-
add_log("Visit completed. Closing browser.")
|
| 46 |
-
browser.close()
|
| 47 |
-
|
| 48 |
-
except Exception as e:
|
| 49 |
-
add_log(f"CRITICAL ERROR: {str(e)}")
|
| 50 |
-
|
| 51 |
-
def run_scheduler():
|
| 52 |
-
visit_and_scroll()
|
| 53 |
-
schedule.every(1).hours.do(visit_and_scroll)
|
| 54 |
-
while True:
|
| 55 |
-
schedule.run_pending()
|
| 56 |
-
time.sleep(60)
|
| 57 |
-
|
| 58 |
-
# Start background thread
|
| 59 |
-
thread = threading.Thread(target=run_scheduler, daemon=True)
|
| 60 |
-
thread.start()
|
| 61 |
-
|
| 62 |
-
def get_logs():
|
| 63 |
-
return "\n".join(reversed(logs))
|
| 64 |
-
|
| 65 |
-
# Gradio Interface fix for v6 warning
|
| 66 |
-
with gr.Blocks() as demo:
|
| 67 |
-
gr.Markdown("# 🚀 Cloud Stay-Alive Bot")
|
| 68 |
-
status_box = gr.Textbox(label="Latest Logs (Top First)", value=get_logs, every=5, lines=15)
|
| 69 |
-
|
| 70 |
-
if __name__ == "__main__":
|
| 71 |
-
# Move theme to launch to fix the Gradio 6 warning
|
| 72 |
-
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|