Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,77 +1,64 @@
|
|
1 |
-
import requests
|
2 |
import discord
|
3 |
-
import
|
4 |
-
import
|
5 |
-
|
6 |
import subprocess
|
7 |
-
import
|
8 |
-
from PIL import Image
|
9 |
-
import time
|
10 |
|
11 |
-
#
|
12 |
-
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s:%(levelname)s:%(name)s: %(message)s', handlers=[logging.StreamHandler()])
|
13 |
-
|
14 |
-
# μΈν
νΈ μ€μ
|
15 |
intents = discord.Intents.default()
|
16 |
intents.message_content = True
|
|
|
|
|
|
|
|
|
17 |
|
18 |
-
#
|
19 |
-
|
20 |
|
21 |
-
|
22 |
-
|
|
|
23 |
|
24 |
-
|
25 |
-
|
|
|
|
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
logging.debug(f'ν둬ννΈ λ²μ μ€: {prompt}')
|
30 |
-
translation = translator(prompt, max_length=512)
|
31 |
-
translated_text = translation[0]['translation_text']
|
32 |
-
logging.debug(f'λ²μλ ν
μ€νΈ: {translated_text}')
|
33 |
-
return translated_text
|
34 |
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
|
47 |
-
|
48 |
-
|
49 |
-
logging.info(f'{self.user}λ‘ λ‘κ·ΈμΈλμμ΅λλ€!')
|
50 |
-
subprocess.Popen(["python", "web.py"]) # λ³λμ Python μ€ν¬λ¦½νΈ μ€ν
|
51 |
-
logging.info("web.py μλ²κ° μμλμμ΅λλ€.")
|
52 |
|
53 |
-
|
54 |
-
|
55 |
-
return
|
56 |
-
if message.content.startswith('!image '):
|
57 |
-
self.is_processing = True
|
58 |
-
try:
|
59 |
-
prompt = message.content[len('!image '):]
|
60 |
-
prompt_en = translate_prompt(prompt)
|
61 |
-
image_url = generate_image(prompt_en, negative_prompt)
|
62 |
-
if image_url:
|
63 |
-
await message.channel.send(f"<@{message.author.id}> λμ΄ μμ²νμ μ΄λ―Έμ§μ
λλ€: {image_url}")
|
64 |
-
else:
|
65 |
-
await message.channel.send(f"<@{message.author.id}> μ΄λ―Έμ§ μμ±μ μ€ν¨νμμ΅λλ€.")
|
66 |
-
finally:
|
67 |
-
self.is_processing = False
|
68 |
-
else:
|
69 |
-
await message.channel.send('μ¬λ°λ₯Έ λͺ
λ Ήμ΄λ₯Ό μ
λ ₯ν΄ μ£ΌμΈμ. μ) "!image κ·μ¬μ΄ κ³ μμ΄κ° μ μ μκ³ μλ€." λ±μΌλ‘ μ
λ ₯νμλ©΄ μ΄λ―Έμ§κ° μμ±λ©λλ€.')
|
70 |
|
71 |
-
# λ΄ μ€ν
|
72 |
if __name__ == "__main__":
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
|
|
|
|
|
77 |
|
|
|
|
|
|
|
|
1 |
import discord
|
2 |
+
from discord.ext import commands
|
3 |
+
from gradio_client import Client
|
4 |
+
import multiprocessing
|
5 |
import subprocess
|
6 |
+
import sys
|
|
|
|
|
7 |
|
8 |
+
# Set up Discord bot
|
|
|
|
|
|
|
9 |
intents = discord.Intents.default()
|
10 |
intents.message_content = True
|
11 |
+
bot = commands.Bot(command_prefix='!', intents=intents)
|
12 |
+
|
13 |
+
# Gradio client setup
|
14 |
+
gradio_client = Client("http://211.233.58.202:7960/")
|
15 |
|
16 |
+
# Discord channel ID to monitor
|
17 |
+
CHANNEL_ID = 1269529561914413106
|
18 |
|
19 |
+
@bot.event
|
20 |
+
async def on_ready():
|
21 |
+
print(f'{bot.user} has connected to Discord!')
|
22 |
|
23 |
+
@bot.event
|
24 |
+
async def on_message(message):
|
25 |
+
if message.author == bot.user:
|
26 |
+
return
|
27 |
|
28 |
+
if message.channel.id != CHANNEL_ID and not isinstance(message.channel, discord.Thread):
|
29 |
+
return
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
+
# Generate image using Gradio client
|
32 |
+
try:
|
33 |
+
result = gradio_client.predict(
|
34 |
+
prompt=message.content,
|
35 |
+
seed=123,
|
36 |
+
randomize_seed=False,
|
37 |
+
width=1024,
|
38 |
+
height=576,
|
39 |
+
guidance_scale=5,
|
40 |
+
num_inference_steps=30,
|
41 |
+
api_name="/infer_t2i"
|
42 |
+
)
|
43 |
+
|
44 |
+
# Send the generated image back to the user
|
45 |
+
await message.channel.send(file=discord.File(result))
|
46 |
+
except Exception as e:
|
47 |
+
await message.channel.send(f"An error occurred: {str(e)}")
|
48 |
|
49 |
+
def run_web():
|
50 |
+
subprocess.run([sys.executable, "web.py"])
|
|
|
|
|
|
|
51 |
|
52 |
+
def run_discord_bot():
|
53 |
+
bot.run('MTIyODQyNTQxNDk0MzQ0MTEwNw.Gfd_ri.rrG_6-Sfp0FYvSIbv-zZ98dpHI-G_Fh9MFCzco')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
|
|
|
55 |
if __name__ == "__main__":
|
56 |
+
# Start web.py in a separate process
|
57 |
+
web_process = multiprocessing.Process(target=run_web)
|
58 |
+
web_process.start()
|
59 |
|
60 |
+
# Run the Discord bot
|
61 |
+
run_discord_bot()
|
62 |
|
63 |
+
# Wait for the web process to finish (which it likely won't)
|
64 |
+
web_process.join()
|