seawolf2357 commited on
Commit
021392e
β€’
1 Parent(s): e6b5c32

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -1
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
- image_path = await self.generate_image(prompt)
 
 
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')