testing
Browse files- Dockerfile +16 -14
- app.py +14 -14
Dockerfile
CHANGED
@@ -6,27 +6,29 @@ RUN useradd -m -u 1000 user
|
|
6 |
# Switch to the "user" user
|
7 |
USER user
|
8 |
|
9 |
-
# Set home to the user's home directory
|
10 |
ENV HOME=/home/user \
|
11 |
-
|
12 |
-
|
13 |
-
# Set the working directory to the user's home directory
|
14 |
-
WORKDIR $HOME/app
|
15 |
|
|
|
16 |
WORKDIR /app
|
17 |
|
18 |
-
|
|
|
19 |
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
20 |
|
21 |
-
|
|
|
|
|
|
|
|
|
22 |
|
23 |
-
|
24 |
-
EXPOSE 80
|
25 |
ENV PYTHONUNBUFFERED=1 \
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
|
31 |
-
|
32 |
CMD ["python", "app.py"]
|
|
|
6 |
# Switch to the "user" user
|
7 |
USER user
|
8 |
|
9 |
+
# Set home to the user's home directory and update PATH
|
10 |
ENV HOME=/home/user \
|
11 |
+
PATH=/home/user/.local/bin:$PATH
|
|
|
|
|
|
|
12 |
|
13 |
+
# Set the working directory to /app
|
14 |
WORKDIR /app
|
15 |
|
16 |
+
# Copy requirements.txt and install dependencies
|
17 |
+
COPY --chown=user: ./requirements.txt ./requirements.txt
|
18 |
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
19 |
|
20 |
+
# Copy the rest of the application code
|
21 |
+
COPY --chown=user: . .
|
22 |
+
|
23 |
+
# Expose necessary ports
|
24 |
+
EXPOSE 7860 80
|
25 |
|
26 |
+
# Set environment variables
|
|
|
27 |
ENV PYTHONUNBUFFERED=1 \
|
28 |
+
GRADIO_ALLOW_FLAGGING=never \
|
29 |
+
GRADIO_NUM_PORTS=1 \
|
30 |
+
GRADIO_SERVER_NAME=0.0.0.0 \
|
31 |
+
SYSTEM=spaces
|
32 |
|
33 |
+
# Specify the command to run the application
|
34 |
CMD ["python", "app.py"]
|
app.py
CHANGED
@@ -1,5 +1,3 @@
|
|
1 |
-
# discord_bot.py
|
2 |
-
|
3 |
import asyncio
|
4 |
import logging
|
5 |
import os
|
@@ -7,11 +5,12 @@ import re
|
|
7 |
import sys
|
8 |
|
9 |
import discord
|
10 |
-
import requests
|
|
|
11 |
from discord import Embed
|
12 |
from discord.ext import commands
|
13 |
from gradio_client import Client
|
14 |
-
from gradio_client.exceptions import AppError
|
15 |
|
16 |
# **Fetch Discord Bot Token from Environment Variable**
|
17 |
DISCORD_BOT_TOKEN = os.environ.get('DISCORD_BOT_TOKEN')
|
@@ -48,14 +47,12 @@ PROMPT_REGEX = re.compile(r'prompt\s*=\s*"(.*?)"')
|
|
48 |
# Initialize the Gradio client with hf_token
|
49 |
GRADIO_CLIENT = Client("Nevaehni/FLUX.1-schnell", hf_token=HF_TOKEN)
|
50 |
|
51 |
-
|
52 |
@bot.event
|
53 |
async def on_ready():
|
54 |
"""Event handler triggered when the bot is ready."""
|
55 |
logger.info(f'Logged in as {bot.user} (ID: {bot.user.id})')
|
56 |
logger.info('------')
|
57 |
|
58 |
-
|
59 |
def parse_prompt(command: str) -> str:
|
60 |
"""
|
61 |
Parse the prompt from the command string.
|
@@ -71,7 +68,6 @@ def parse_prompt(command: str) -> str:
|
|
71 |
return match.group(1).strip()
|
72 |
return ''
|
73 |
|
74 |
-
|
75 |
def create_example_embed() -> Embed:
|
76 |
"""
|
77 |
Create an embed message with an example !generate command.
|
@@ -86,7 +82,6 @@ def create_example_embed() -> Embed:
|
|
86 |
)
|
87 |
return embed
|
88 |
|
89 |
-
|
90 |
@bot.command(name='generate')
|
91 |
async def generate(ctx: commands.Context, *, args: str = None):
|
92 |
"""
|
@@ -221,7 +216,6 @@ async def generate(ctx: commands.Context, *, args: str = None):
|
|
221 |
# Delete the processing message
|
222 |
await processing_message.delete()
|
223 |
|
224 |
-
|
225 |
@bot.event
|
226 |
async def on_command_error(ctx: commands.Context, error):
|
227 |
"""
|
@@ -239,11 +233,9 @@ async def on_command_error(ctx: commands.Context, error):
|
|
239 |
await ctx.send(f"❌ **Error:** {str(error)}")
|
240 |
logger.error(f"Unhandled command error: {str(error)}")
|
241 |
|
242 |
-
|
243 |
async def handle_root(request):
|
244 |
return web.Response(text="DarkMuse GOES VROOOOM", status=200)
|
245 |
|
246 |
-
|
247 |
async def start_web_server():
|
248 |
app = web.Application()
|
249 |
app.router.add_get('/', handle_root)
|
@@ -251,12 +243,20 @@ async def start_web_server():
|
|
251 |
await runner.setup()
|
252 |
site = web.TCPSite(runner, '0.0.0.0', 7860)
|
253 |
await site.start()
|
|
|
254 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
255 |
|
256 |
-
# Run the bot
|
257 |
if __name__ == '__main__':
|
258 |
try:
|
259 |
-
|
260 |
-
bot.loop.create_task(start_web_server())
|
261 |
except Exception as e:
|
262 |
logger.exception(f"Failed to run the bot: {e}")
|
|
|
|
|
|
|
1 |
import asyncio
|
2 |
import logging
|
3 |
import os
|
|
|
5 |
import sys
|
6 |
|
7 |
import discord
|
8 |
+
import requests
|
9 |
+
from aiohttp import web # Added missing import
|
10 |
from discord import Embed
|
11 |
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 Variable**
|
16 |
DISCORD_BOT_TOKEN = os.environ.get('DISCORD_BOT_TOKEN')
|
|
|
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."""
|
53 |
logger.info(f'Logged in as {bot.user} (ID: {bot.user.id})')
|
54 |
logger.info('------')
|
55 |
|
|
|
56 |
def parse_prompt(command: str) -> str:
|
57 |
"""
|
58 |
Parse the prompt from the command string.
|
|
|
68 |
return match.group(1).strip()
|
69 |
return ''
|
70 |
|
|
|
71 |
def create_example_embed() -> Embed:
|
72 |
"""
|
73 |
Create an embed message with an example !generate command.
|
|
|
82 |
)
|
83 |
return embed
|
84 |
|
|
|
85 |
@bot.command(name='generate')
|
86 |
async def generate(ctx: commands.Context, *, args: str = None):
|
87 |
"""
|
|
|
216 |
# Delete the processing message
|
217 |
await processing_message.delete()
|
218 |
|
|
|
219 |
@bot.event
|
220 |
async def on_command_error(ctx: commands.Context, error):
|
221 |
"""
|
|
|
233 |
await ctx.send(f"❌ **Error:** {str(error)}")
|
234 |
logger.error(f"Unhandled command error: {str(error)}")
|
235 |
|
|
|
236 |
async def handle_root(request):
|
237 |
return web.Response(text="DarkMuse GOES VROOOOM", status=200)
|
238 |
|
|
|
239 |
async def start_web_server():
|
240 |
app = web.Application()
|
241 |
app.router.add_get('/', handle_root)
|
|
|
243 |
await runner.setup()
|
244 |
site = web.TCPSite(runner, '0.0.0.0', 7860)
|
245 |
await site.start()
|
246 |
+
logger.info("Web server started on port 7860")
|
247 |
|
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()
|
255 |
+
)
|
256 |
|
257 |
+
# Run the bot and web server concurrently
|
258 |
if __name__ == '__main__':
|
259 |
try:
|
260 |
+
asyncio.run(main())
|
|
|
261 |
except Exception as e:
|
262 |
logger.exception(f"Failed to run the bot: {e}")
|