Spaces:
Runtime error
Runtime error
seawolf2357
commited on
Commit
β’
539a18a
1
Parent(s):
021392e
Update app.py
Browse files
app.py
CHANGED
@@ -28,7 +28,7 @@ model_path = snapshot_download(
|
|
28 |
|
29 |
# λͺ¨λΈ λ‘λ ν¨μ
|
30 |
def load_pipeline(pipeline_type):
|
31 |
-
logging.debug(f'
|
32 |
if pipeline_type == "text2img":
|
33 |
return StableDiffusion3Pipeline.from_pretrained(model_path, torch_dtype=torch.float16, use_fast=True)
|
34 |
elif pipeline_type == "img2img":
|
@@ -40,6 +40,9 @@ device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
|
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):
|
@@ -61,25 +64,31 @@ class MyClient(discord.Client):
|
|
61 |
try:
|
62 |
prompt = message.content[len('!image '):]
|
63 |
prompt_en = translate_prompt(prompt)
|
64 |
-
logging.debug(f'
|
65 |
-
|
66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
finally:
|
68 |
self.is_processing = False
|
69 |
|
70 |
-
async def generate_image(self, prompt):
|
71 |
generator = torch.Generator(device=device).manual_seed(torch.seed())
|
72 |
-
images = self.text2img_pipeline(prompt, num_inference_steps=50, generator=generator)["images"]
|
73 |
image_path = f'/tmp/{uuid.uuid4()}.png'
|
74 |
images[0].save(image_path)
|
75 |
return image_path
|
76 |
|
77 |
# ν둬ννΈ λ²μ ν¨μ
|
78 |
def translate_prompt(prompt):
|
79 |
-
logging.debug(f'
|
80 |
translation = translator(prompt, max_length=512)
|
81 |
translated_text = translation[0]['translation_text']
|
82 |
-
logging.debug(f'
|
83 |
return translated_text
|
84 |
|
85 |
# λμ€μ½λ ν ν° λ° λ΄ μ€ν
|
|
|
28 |
|
29 |
# λͺ¨λΈ λ‘λ ν¨μ
|
30 |
def load_pipeline(pipeline_type):
|
31 |
+
logging.debug(f'νμ΄νλΌμΈ λ‘λ μ€: {pipeline_type}')
|
32 |
if pipeline_type == "text2img":
|
33 |
return StableDiffusion3Pipeline.from_pretrained(model_path, torch_dtype=torch.float16, use_fast=True)
|
34 |
elif pipeline_type == "img2img":
|
|
|
40 |
# λ²μ νμ΄νλΌμΈ μ€μ
|
41 |
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en")
|
42 |
|
43 |
+
# κ³ μ λ λ€κ±°ν°λΈ ν둬ννΈ
|
44 |
+
negative_prompt = "blur, low quality, bad composition, ugly, disfigured, weird colors, low quality, jpeg artifacts, lowres, grainy, deformed structures, blurry, opaque, low contrast, distorted details, details are low"
|
45 |
+
|
46 |
# λμ€μ½λ λ΄ ν΄λμ€
|
47 |
class MyClient(discord.Client):
|
48 |
def __init__(self, *args, **kwargs):
|
|
|
64 |
try:
|
65 |
prompt = message.content[len('!image '):]
|
66 |
prompt_en = translate_prompt(prompt)
|
67 |
+
logging.debug(f'λ²μλ ν둬ννΈ: {prompt_en}')
|
68 |
+
logging.debug(f'κ³ μ λ λ€κ±°ν°λΈ ν둬ννΈ: {negative_prompt}')
|
69 |
+
|
70 |
+
image_path = await self.generate_image(prompt_en, negative_prompt)
|
71 |
+
user_id = message.author.id # μ¬μ©μμ ID μΊ‘μ²
|
72 |
+
await message.channel.send(
|
73 |
+
f"<@{user_id}> λμ΄ μμ²νμ μ΄λ―Έμ§μ
λλ€.",
|
74 |
+
file=discord.File(image_path, 'generated_image.png')
|
75 |
+
)
|
76 |
finally:
|
77 |
self.is_processing = False
|
78 |
|
79 |
+
async def generate_image(self, prompt, negative_prompt):
|
80 |
generator = torch.Generator(device=device).manual_seed(torch.seed())
|
81 |
+
images = self.text2img_pipeline(prompt, negative_prompt=negative_prompt, num_inference_steps=50, generator=generator)["images"]
|
82 |
image_path = f'/tmp/{uuid.uuid4()}.png'
|
83 |
images[0].save(image_path)
|
84 |
return image_path
|
85 |
|
86 |
# ν둬ννΈ λ²μ ν¨μ
|
87 |
def translate_prompt(prompt):
|
88 |
+
logging.debug(f'ν둬ννΈ λ²μ μ€: {prompt}')
|
89 |
translation = translator(prompt, max_length=512)
|
90 |
translated_text = translation[0]['translation_text']
|
91 |
+
logging.debug(f'λ²μλ ν
μ€νΈ: {translated_text}')
|
92 |
return translated_text
|
93 |
|
94 |
# λμ€μ½λ ν ν° λ° λ΄ μ€ν
|