testing
Browse files- .idea/.gitignore +8 -0
- .idea/DarkMuse.iml +10 -0
- .idea/inspectionProfiles/Project_Default.xml +13 -0
- .idea/inspectionProfiles/profiles_settings.xml +6 -0
- .idea/modules.xml +8 -0
- .idea/vcs.xml +6 -0
- app.py +31 -1
.idea/.gitignore
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Default ignored files
|
2 |
+
/shelf/
|
3 |
+
/workspace.xml
|
4 |
+
# Editor-based HTTP Client requests
|
5 |
+
/httpRequests/
|
6 |
+
# Datasource local storage ignored files
|
7 |
+
/dataSources/
|
8 |
+
/dataSources.local.xml
|
.idea/DarkMuse.iml
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<module type="PYTHON_MODULE" version="4">
|
3 |
+
<component name="NewModuleRootManager">
|
4 |
+
<content url="file://$MODULE_DIR$">
|
5 |
+
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
6 |
+
</content>
|
7 |
+
<orderEntry type="inheritedJdk" />
|
8 |
+
<orderEntry type="sourceFolder" forTests="false" />
|
9 |
+
</component>
|
10 |
+
</module>
|
.idea/inspectionProfiles/Project_Default.xml
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<component name="InspectionProjectProfileManager">
|
2 |
+
<profile version="1.0">
|
3 |
+
<option name="myName" value="Project Default" />
|
4 |
+
<inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
|
5 |
+
<inspection_tool class="PyUnresolvedReferencesInspection" enabled="true" level="WARNING" enabled_by_default="true">
|
6 |
+
<option name="ignoredIdentifiers">
|
7 |
+
<list>
|
8 |
+
<option value="str.*" />
|
9 |
+
</list>
|
10 |
+
</option>
|
11 |
+
</inspection_tool>
|
12 |
+
</profile>
|
13 |
+
</component>
|
.idea/inspectionProfiles/profiles_settings.xml
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<component name="InspectionProjectProfileManager">
|
2 |
+
<settings>
|
3 |
+
<option name="USE_PROJECT_PROFILE" value="false" />
|
4 |
+
<version value="1.0" />
|
5 |
+
</settings>
|
6 |
+
</component>
|
.idea/modules.xml
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<project version="4">
|
3 |
+
<component name="ProjectModuleManager">
|
4 |
+
<modules>
|
5 |
+
<module fileurl="file://$PROJECT_DIR$/.idea/DarkMuse.iml" filepath="$PROJECT_DIR$/.idea/DarkMuse.iml" />
|
6 |
+
</modules>
|
7 |
+
</component>
|
8 |
+
</project>
|
.idea/vcs.xml
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<project version="4">
|
3 |
+
<component name="VcsDirectoryMappings">
|
4 |
+
<mapping directory="" vcs="Git" />
|
5 |
+
</component>
|
6 |
+
</project>
|
app.py
CHANGED
@@ -3,6 +3,8 @@ import logging
|
|
3 |
import os
|
4 |
import re
|
5 |
import sys
|
|
|
|
|
6 |
|
7 |
import discord
|
8 |
import requests
|
@@ -12,7 +14,7 @@ from discord.ext import commands
|
|
12 |
from gradio_client import Client
|
13 |
from gradio_client.exceptions import AppError
|
14 |
|
15 |
-
# **Fetch Discord Bot Token from Environment
|
16 |
DISCORD_BOT_TOKEN = os.environ.get('DISCORD_BOT_TOKEN')
|
17 |
HF_TOKEN = os.environ.get('HF_TOKEN') # Fetch the HF_TOKEN
|
18 |
|
@@ -47,6 +49,9 @@ PROMPT_REGEX = re.compile(r'prompt\s*=\s*"(.*?)"', re.DOTALL)
|
|
47 |
# Initialize the Gradio client with hf_token
|
48 |
GRADIO_CLIENT = Client("Nevaehni/FLUX.1-schnell", hf_token=HF_TOKEN)
|
49 |
|
|
|
|
|
|
|
50 |
@bot.event
|
51 |
async def on_ready():
|
52 |
"""Event handler triggered when the bot is ready."""
|
@@ -248,7 +253,32 @@ async def start_web_server():
|
|
248 |
async def start_bot():
|
249 |
await bot.start(DISCORD_BOT_TOKEN)
|
250 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
251 |
async def main():
|
|
|
|
|
|
|
252 |
await asyncio.gather(
|
253 |
start_bot(),
|
254 |
start_web_server()
|
|
|
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
|
|
|
14 |
from gradio_client import Client
|
15 |
from gradio_client.exceptions import AppError
|
16 |
|
17 |
+
# **Fetch Discord Bot Token and Hugging Face Token from Environment Variables**
|
18 |
DISCORD_BOT_TOKEN = os.environ.get('DISCORD_BOT_TOKEN')
|
19 |
HF_TOKEN = os.environ.get('HF_TOKEN') # Fetch the HF_TOKEN
|
20 |
|
|
|
49 |
# Initialize the Gradio client with hf_token
|
50 |
GRADIO_CLIENT = Client("Nevaehni/FLUX.1-schnell", hf_token=HF_TOKEN)
|
51 |
|
52 |
+
# Initialize Hugging Face API client
|
53 |
+
hf_api = HfApi()
|
54 |
+
|
55 |
@bot.event
|
56 |
async def on_ready():
|
57 |
"""Event handler triggered when the bot is ready."""
|
|
|
253 |
async def start_bot():
|
254 |
await bot.start(DISCORD_BOT_TOKEN)
|
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
|
280 |
+
asyncio.create_task(schedule_restart())
|
281 |
+
# Run the bot and web server concurrently
|
282 |
await asyncio.gather(
|
283 |
start_bot(),
|
284 |
start_web_server()
|