Nevaehni commited on
Commit
ba5e9de
1 Parent(s): 7b1582f
Files changed (3) hide show
  1. .idea/DarkMuse.iml +4 -0
  2. .idea/misc.xml +7 -0
  3. app.py +11 -13
.idea/DarkMuse.iml CHANGED
@@ -7,4 +7,8 @@
7
  <orderEntry type="inheritedJdk" />
8
  <orderEntry type="sourceFolder" forTests="false" />
9
  </component>
 
 
 
 
10
  </module>
 
7
  <orderEntry type="inheritedJdk" />
8
  <orderEntry type="sourceFolder" forTests="false" />
9
  </component>
10
+ <component name="PyDocumentationSettings">
11
+ <option name="format" value="PLAIN" />
12
+ <option name="myDocStringFormat" value="Plain" />
13
+ </component>
14
  </module>
.idea/misc.xml ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="Black">
4
+ <option name="sdkName" value="Python 3.10 (DarkMuse)" />
5
+ </component>
6
+ <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (DarkMuse)" project-jdk-type="Python SDK" />
7
+ </project>
app.py CHANGED
@@ -3,8 +3,8 @@ import logging
3
  import os
4
  import re
5
  import sys
6
- import datetime # Added for scheduling
7
- from huggingface_hub import HfApi # Added for Hugging Face API
8
 
9
  import discord
10
  import requests
@@ -255,25 +255,23 @@ async def start_bot():
255
 
256
  async def schedule_restart():
257
  """
258
- Schedule the bot to restart the Hugging Face Space every day at 05:00.
 
259
  """
260
- space_name = "Nevaehni/FLUX.1-schnell" # Replace with your actual space name
 
 
261
  while True:
262
- now = datetime.datetime.now()
263
- target_time = now.replace(hour=5, minute=0, second=0, microsecond=0)
264
- if now >= target_time:
265
- target_time += datetime.timedelta(days=1)
266
- wait_seconds = (target_time - now).total_seconds()
267
- logger.info(f"Scheduled space restart in {wait_seconds} seconds at {target_time.strftime('%Y-%m-%d %H:%M:%S')}.")
268
- await asyncio.sleep(wait_seconds)
269
  try:
270
  logger.info("Attempting to restart the Hugging Face Space...")
271
- hf_api.restart_space(space_id=space_name, token=HF_TOKEN)
272
  logger.info("Space restarted successfully.")
273
  except Exception as e:
274
  logger.error(f"Failed to restart space: {e}")
275
  # Optional: Add a short delay to prevent rapid retries in case of failure
276
- await asyncio.sleep(60)
277
 
278
  async def main():
279
  # Start the scheduler as a background task
 
3
  import os
4
  import re
5
  import sys
6
+ import datetime # For scheduling
7
+ from huggingface_hub import HfApi # For Hugging Face API
8
 
9
  import discord
10
  import requests
 
255
 
256
  async def schedule_restart():
257
  """
258
+ Schedule the bot to restart the Hugging Face Space at a specified interval.
259
+ For testing purposes, this function restarts the Space every minute.
260
  """
261
+ space_id = "Nevaehni/FLUX.1-schnell" # Replace with your actual space ID
262
+ restart_interval_seconds = 60 # Restart every 60 seconds (1 minute) for testing
263
+
264
  while True:
265
+ logger.info(f"Scheduled space restart in {restart_interval_seconds} seconds.")
266
+ await asyncio.sleep(restart_interval_seconds)
 
 
 
 
 
267
  try:
268
  logger.info("Attempting to restart the Hugging Face Space...")
269
+ hf_api.restart_space(space_id=space_id, token=HF_TOKEN)
270
  logger.info("Space restarted successfully.")
271
  except Exception as e:
272
  logger.error(f"Failed to restart space: {e}")
273
  # Optional: Add a short delay to prevent rapid retries in case of failure
274
+ await asyncio.sleep(5) # Wait 5 seconds before the next restart cycle
275
 
276
  async def main():
277
  # Start the scheduler as a background task