seawolf2357 commited on
Commit
820b30b
1 Parent(s): eeb1a34

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -23
app.py CHANGED
@@ -6,6 +6,7 @@ import subprocess
6
  from huggingface_hub import InferenceClient
7
  from PIL import Image
8
  import io
 
9
 
10
  # 로깅 설정
11
  logging.basicConfig(level=logging.DEBUG, format='%(asctime)s:%(levelname)s:%(name)s: %(message)s', handlers=[logging.StreamHandler()])
@@ -20,9 +21,6 @@ intents.guild_messages = True
20
  # 추론 API 클라이언트 설정
21
  hf_client = InferenceClient(token=os.getenv("HF_TOKEN"))
22
 
23
- # 특정 채널 ID
24
- SPECIFIC_CHANNEL_ID = int(os.getenv("DISCORD_CHANNEL_ID"))
25
-
26
  class MyClient(discord.Client):
27
  def __init__(self, *args, **kwargs):
28
  super().__init__(*args, **kwargs)
@@ -30,7 +28,7 @@ class MyClient(discord.Client):
30
 
31
  async def on_ready(self):
32
  logging.info(f'{self.user} has logged in!')
33
- subprocess.Popen(["python", "web.py"]) # Start the web.py server as a separate process
34
  logging.info("Web.py server has been started.")
35
 
36
  async def on_message(self, message):
@@ -50,25 +48,6 @@ class MyClient(discord.Client):
50
  finally:
51
  self.is_processing = False
52
 
53
- async def generate_image(prompt):
54
- try:
55
- # 모델 호출
56
- response = hf_client(inputs={"inputs": prompt}, options={"wait_for_model": True}) # options는 필요에 따라 조정 가능
57
- image_data = response.get('images', [None])[0] # 응답에서 이미지 데이터 추출
58
- if image_data:
59
- image_bytes = io.BytesIO(base64.b64decode(image_data))
60
- image = Image.open(image_bytes)
61
- image_path = "output.png"
62
- image.save(image_path)
63
- return image_path
64
- else:
65
- raise ValueError("No image data received.")
66
- except Exception as e:
67
- logging.error(f"Failed to generate image: {str(e)}")
68
- return None
69
-
70
-
71
-
72
  async def send_image(channel, image_path):
73
  file = discord.File(image_path)
74
  await channel.send(file=file)
 
6
  from huggingface_hub import InferenceClient
7
  from PIL import Image
8
  import io
9
+ import base64
10
 
11
  # 로깅 설정
12
  logging.basicConfig(level=logging.DEBUG, format='%(asctime)s:%(levelname)s:%(name)s: %(message)s', handlers=[logging.StreamHandler()])
 
21
  # 추론 API 클라이언트 설정
22
  hf_client = InferenceClient(token=os.getenv("HF_TOKEN"))
23
 
 
 
 
24
  class MyClient(discord.Client):
25
  def __init__(self, *args, **kwargs):
26
  super().__init__(*args, **kwargs)
 
28
 
29
  async def on_ready(self):
30
  logging.info(f'{self.user} has logged in!')
31
+ subprocess.Popen(["python", "web.py"])
32
  logging.info("Web.py server has been started.")
33
 
34
  async def on_message(self, message):
 
48
  finally:
49
  self.is_processing = False
50
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  async def send_image(channel, image_path):
52
  file = discord.File(image_path)
53
  await channel.send(file=file)