Update app.py
Browse files
app.py
CHANGED
@@ -1,36 +1,22 @@
|
|
1 |
import discord
|
2 |
import os
|
3 |
-
import threading
|
4 |
import gradio as gr
|
5 |
-
import
|
6 |
-
import json
|
7 |
-
import random
|
8 |
-
import time
|
9 |
-
import re
|
10 |
-
from discord import Embed, Color
|
11 |
from discord.ext import commands
|
12 |
from gradio_client import Client
|
13 |
from PIL import Image
|
14 |
-
#from ratelimiter import RateLimiter
|
15 |
-
|
16 |
-
import asyncio
|
17 |
-
import httpx
|
18 |
-
|
19 |
-
from tasks import make_request_async
|
20 |
|
21 |
DFIF_TOKEN = os.getenv('HF_TOKEN')
|
22 |
DISCORD_TOKEN = os.environ.get("GRADIOTEST_TOKEN", None)
|
23 |
|
24 |
jojogan = Client("akhaliq/JoJoGAN", DFIF_TOKEN)
|
25 |
|
26 |
-
|
27 |
intents = discord.Intents.default()
|
28 |
intents.message_content = True
|
29 |
|
30 |
bot = commands.Bot(command_prefix='!', intents=intents)
|
31 |
|
32 |
|
33 |
-
#---------------------------------------------------------------------------------------------------------------------------
|
34 |
async def jojo(ctx):
|
35 |
start_time = time.time()
|
36 |
style = 'JoJo'
|
@@ -40,30 +26,36 @@ async def jojo(ctx):
|
|
40 |
generation_time = end_time - start_time
|
41 |
await ctx.send(f"{style} image generated in {generation_time:.2f} seconds.")
|
42 |
await ctx.send(file=discord.File(im))
|
43 |
-
|
44 |
|
45 |
@bot.command()
|
46 |
-
async def command(ctx):
|
47 |
-
|
48 |
-
|
49 |
-
for
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
for thread in threads:
|
58 |
-
thread.join()
|
59 |
|
60 |
def run_bot():
|
61 |
bot.run(DISCORD_TOKEN)
|
62 |
|
63 |
-
threading.Thread(target=run_bot).start()
|
64 |
|
65 |
-
def
|
66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
|
68 |
-
|
69 |
-
demo.launch()
|
|
|
1 |
import discord
|
2 |
import os
|
|
|
3 |
import gradio as gr
|
4 |
+
import asyncio
|
|
|
|
|
|
|
|
|
|
|
5 |
from discord.ext import commands
|
6 |
from gradio_client import Client
|
7 |
from PIL import Image
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
DFIF_TOKEN = os.getenv('HF_TOKEN')
|
10 |
DISCORD_TOKEN = os.environ.get("GRADIOTEST_TOKEN", None)
|
11 |
|
12 |
jojogan = Client("akhaliq/JoJoGAN", DFIF_TOKEN)
|
13 |
|
|
|
14 |
intents = discord.Intents.default()
|
15 |
intents.message_content = True
|
16 |
|
17 |
bot = commands.Bot(command_prefix='!', intents=intents)
|
18 |
|
19 |
|
|
|
20 |
async def jojo(ctx):
|
21 |
start_time = time.time()
|
22 |
style = 'JoJo'
|
|
|
26 |
generation_time = end_time - start_time
|
27 |
await ctx.send(f"{style} image generated in {generation_time:.2f} seconds.")
|
28 |
await ctx.send(file=discord.File(im))
|
29 |
+
|
30 |
|
31 |
@bot.command()
|
32 |
+
async def command(ctx, num_requests: int):
|
33 |
+
tasks = []
|
34 |
+
|
35 |
+
for _ in range(num_requests):
|
36 |
+
task = asyncio.create_task(jojo(ctx))
|
37 |
+
tasks.append(task)
|
38 |
+
|
39 |
+
await asyncio.gather(*tasks)
|
40 |
+
await ctx.send("Command executed.")
|
41 |
+
|
|
|
|
|
|
|
42 |
|
43 |
def run_bot():
|
44 |
bot.run(DISCORD_TOKEN)
|
45 |
|
|
|
46 |
|
47 |
+
async def run_gradio_interface():
|
48 |
+
def greet(name):
|
49 |
+
return "Hello " + name + "!"
|
50 |
+
|
51 |
+
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
|
52 |
+
await demo.launch()
|
53 |
+
|
54 |
+
|
55 |
+
async def main():
|
56 |
+
bot_task = asyncio.create_task(run_bot())
|
57 |
+
gradio_task = asyncio.create_task(run_gradio_interface())
|
58 |
+
await asyncio.gather(bot_task, gradio_task)
|
59 |
+
|
60 |
|
61 |
+
asyncio.run(main())
|
|