Spaces:
Runtime error
Runtime error
seawolf2357
commited on
Commit
β’
021392e
1
Parent(s):
e6b5c32
Update app.py
Browse files
app.py
CHANGED
@@ -3,8 +3,10 @@ import logging
|
|
3 |
import os
|
4 |
import uuid
|
5 |
import torch
|
|
|
6 |
from huggingface_hub import snapshot_download
|
7 |
from diffusers import StableDiffusion3Pipeline, StableDiffusion3Img2ImgPipeline
|
|
|
8 |
|
9 |
# λ‘κΉ
μ€μ
|
10 |
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s:%(levelname)s:%(name)s: %(message)s', handlers=[logging.StreamHandler()])
|
@@ -35,6 +37,9 @@ def load_pipeline(pipeline_type):
|
|
35 |
# λλ°μ΄μ€ μ€μ
|
36 |
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
37 |
|
|
|
|
|
|
|
38 |
# λμ€μ½λ λ΄ ν΄λμ€
|
39 |
class MyClient(discord.Client):
|
40 |
def __init__(self, *args, **kwargs):
|
@@ -45,6 +50,8 @@ class MyClient(discord.Client):
|
|
45 |
|
46 |
async def on_ready(self):
|
47 |
logging.info(f'{self.user}λ‘ λ‘κ·ΈμΈλμμ΅λλ€!')
|
|
|
|
|
48 |
|
49 |
async def on_message(self, message):
|
50 |
if message.author == self.user:
|
@@ -53,7 +60,9 @@ class MyClient(discord.Client):
|
|
53 |
self.is_processing = True
|
54 |
try:
|
55 |
prompt = message.content[len('!image '):]
|
56 |
-
|
|
|
|
|
57 |
await message.channel.send(file=discord.File(image_path, 'generated_image.png'))
|
58 |
finally:
|
59 |
self.is_processing = False
|
@@ -65,6 +74,14 @@ class MyClient(discord.Client):
|
|
65 |
images[0].save(image_path)
|
66 |
return image_path
|
67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
# λμ€μ½λ ν ν° λ° λ΄ μ€ν
|
69 |
if __name__ == "__main__":
|
70 |
discord_token = os.getenv('DISCORD_TOKEN')
|
|
|
3 |
import os
|
4 |
import uuid
|
5 |
import torch
|
6 |
+
import subprocess
|
7 |
from huggingface_hub import snapshot_download
|
8 |
from diffusers import StableDiffusion3Pipeline, StableDiffusion3Img2ImgPipeline
|
9 |
+
from transformers import pipeline
|
10 |
|
11 |
# λ‘κΉ
μ€μ
|
12 |
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s:%(levelname)s:%(name)s: %(message)s', handlers=[logging.StreamHandler()])
|
|
|
37 |
# λλ°μ΄μ€ μ€μ
|
38 |
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
39 |
|
40 |
+
# λ²μ νμ΄νλΌμΈ μ€μ
|
41 |
+
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en")
|
42 |
+
|
43 |
# λμ€μ½λ λ΄ ν΄λμ€
|
44 |
class MyClient(discord.Client):
|
45 |
def __init__(self, *args, **kwargs):
|
|
|
50 |
|
51 |
async def on_ready(self):
|
52 |
logging.info(f'{self.user}λ‘ λ‘κ·ΈμΈλμμ΅λλ€!')
|
53 |
+
subprocess.Popen(["python", "web.py"])
|
54 |
+
logging.info("web.py μλ²κ° μμλμμ΅λλ€.")
|
55 |
|
56 |
async def on_message(self, message):
|
57 |
if message.author == self.user:
|
|
|
60 |
self.is_processing = True
|
61 |
try:
|
62 |
prompt = message.content[len('!image '):]
|
63 |
+
prompt_en = translate_prompt(prompt)
|
64 |
+
logging.debug(f'Translated prompt: {prompt_en}')
|
65 |
+
image_path = await self.generate_image(prompt_en)
|
66 |
await message.channel.send(file=discord.File(image_path, 'generated_image.png'))
|
67 |
finally:
|
68 |
self.is_processing = False
|
|
|
74 |
images[0].save(image_path)
|
75 |
return image_path
|
76 |
|
77 |
+
# ν둬ννΈ λ²μ ν¨μ
|
78 |
+
def translate_prompt(prompt):
|
79 |
+
logging.debug(f'Translating prompt: {prompt}')
|
80 |
+
translation = translator(prompt, max_length=512)
|
81 |
+
translated_text = translation[0]['translation_text']
|
82 |
+
logging.debug(f'Translated text: {translated_text}')
|
83 |
+
return translated_text
|
84 |
+
|
85 |
# λμ€μ½λ ν ν° λ° λ΄ μ€ν
|
86 |
if __name__ == "__main__":
|
87 |
discord_token = os.getenv('DISCORD_TOKEN')
|