Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
test auto restart (20:05)
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ import os
|
|
2 |
import io
|
3 |
import re
|
4 |
import csv
|
|
|
5 |
import json
|
6 |
import time
|
7 |
import random
|
@@ -13,6 +14,7 @@ import secrets
|
|
13 |
import aiohttp
|
14 |
import gspread
|
15 |
import datetime
|
|
|
16 |
import requests
|
17 |
import threading
|
18 |
import gradio_client
|
@@ -44,14 +46,12 @@ intents = discord.Intents.all()
|
|
44 |
bot = commands.Bot(command_prefix='!', intents=intents)
|
45 |
|
46 |
|
47 |
-
|
48 |
-
## testing this, restart bot on errors
|
49 |
def restart_bot():
|
50 |
print("Restarting bot...")
|
51 |
os.execv(sys.executable, ['python'] + sys.argv)
|
52 |
|
53 |
|
54 |
-
|
55 |
@bot.event
|
56 |
async def on_ready():
|
57 |
"""import data from google sheets -> HF Space df (doesn't make API call this way, as it's read-only)"""
|
@@ -92,7 +92,6 @@ async def give_verified_roles():
|
|
92 |
org_link = "https://huggingface.co/organizations/discord-community/share/wPKRAHYbAlaEaCxUxcqVyaaaeZcYagDvqc"
|
93 |
invite_message = "Click to join our community org on the HF Hub!"
|
94 |
|
95 |
-
|
96 |
# Cache members in the guild
|
97 |
await guild.chunk()
|
98 |
|
@@ -120,18 +119,31 @@ async def give_verified_roles():
|
|
120 |
await asyncio.sleep(10)
|
121 |
|
122 |
except Exception as e:
|
123 |
-
print(f"Error encountered
|
124 |
-
asyncio.sleep(5)
|
125 |
-
restart_bot()
|
126 |
-
|
127 |
await asyncio.sleep(60)
|
128 |
|
129 |
|
130 |
-
#
|
131 |
def run_bot():
|
132 |
bot.run(DISCORD_TOKEN)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
133 |
threading.Thread(target=run_bot).start()
|
|
|
|
|
|
|
|
|
134 |
def greet(name):
|
135 |
return "Hello " + name + "!"
|
136 |
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
|
137 |
-
demo.launch()
|
|
|
2 |
import io
|
3 |
import re
|
4 |
import csv
|
5 |
+
import sys
|
6 |
import json
|
7 |
import time
|
8 |
import random
|
|
|
14 |
import aiohttp
|
15 |
import gspread
|
16 |
import datetime
|
17 |
+
import schedule
|
18 |
import requests
|
19 |
import threading
|
20 |
import gradio_client
|
|
|
46 |
bot = commands.Bot(command_prefix='!', intents=intents)
|
47 |
|
48 |
|
49 |
+
## testing restart
|
|
|
50 |
def restart_bot():
|
51 |
print("Restarting bot...")
|
52 |
os.execv(sys.executable, ['python'] + sys.argv)
|
53 |
|
54 |
|
|
|
55 |
@bot.event
|
56 |
async def on_ready():
|
57 |
"""import data from google sheets -> HF Space df (doesn't make API call this way, as it's read-only)"""
|
|
|
92 |
org_link = "https://huggingface.co/organizations/discord-community/share/wPKRAHYbAlaEaCxUxcqVyaaaeZcYagDvqc"
|
93 |
invite_message = "Click to join our community org on the HF Hub!"
|
94 |
|
|
|
95 |
# Cache members in the guild
|
96 |
await guild.chunk()
|
97 |
|
|
|
119 |
await asyncio.sleep(10)
|
120 |
|
121 |
except Exception as e:
|
122 |
+
print(f"Error encountered: {e}")
|
|
|
|
|
|
|
123 |
await asyncio.sleep(60)
|
124 |
|
125 |
|
126 |
+
# Function to run the bot in a thread
|
127 |
def run_bot():
|
128 |
bot.run(DISCORD_TOKEN)
|
129 |
+
|
130 |
+
|
131 |
+
# Function to schedule the bot restart at midnight
|
132 |
+
def schedule_restart():
|
133 |
+
schedule.every().day.at("20:05").do(restart_bot)
|
134 |
+
|
135 |
+
while True:
|
136 |
+
schedule.run_pending()
|
137 |
+
time.sleep(1)
|
138 |
+
|
139 |
+
|
140 |
+
# Launch the bot and restart scheduler in separate threads
|
141 |
threading.Thread(target=run_bot).start()
|
142 |
+
threading.Thread(target=schedule_restart).start()
|
143 |
+
|
144 |
+
|
145 |
+
# Example Gradio interface
|
146 |
def greet(name):
|
147 |
return "Hello " + name + "!"
|
148 |
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
|
149 |
+
demo.launch()
|