fantos commited on
Commit
6b59d85
Β·
verified Β·
1 Parent(s): 336650b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -21
app.py CHANGED
@@ -20,10 +20,7 @@ if not REPL_TOKEN:
20
  os.environ["REPLICATE_API_TOKEN"] = REPL_TOKEN
21
 
22
  # ── λͺ¨λΈ ────────────────────────────────────────────────────
23
- MODEL = (
24
- "bytedance/sdxl-lightning-4step:"
25
- "6f7a773af6fc3e8de9d5a3c00be77c17308914bf67772726aff83496ba1e3bbe"
26
- )
27
 
28
  # ── λ²ˆμ—­ νŒŒμ΄ν”„λΌμΈ (CPU) ───────────────────────────────────
29
  translator_kwargs = {"device": -1}
@@ -56,7 +53,7 @@ logging.basicConfig(
56
  intents = discord.Intents.default()
57
  intents.message_content = True # λ©”μ‹œμ§€ μ½˜ν…μΈ  읽기
58
 
59
- class ImageBot(discord.Client):
60
  async def on_ready(self):
61
  logging.info(f"Logged in as {self.user} (id={self.user.id})")
62
  # web.py 병렬 μ‹€ν–‰
@@ -80,28 +77,33 @@ class ImageBot(discord.Client):
80
 
81
  # ── Replicate 호좜 ──────────────────────────────────
82
  def run_replicate():
83
- return list(replicate.run(MODEL, input={"prompt": prompt_en}))
 
84
 
85
  try:
86
- images = await asyncio.get_running_loop().run_in_executor(None, run_replicate)
87
  except Exception as e:
88
  logging.error(f"Replicate error: {e}")
89
- await message.reply("⚠️ 이미지 생성 μ‹€νŒ¨!")
90
  return
91
 
92
- # ── 이미지 Discord 전솑 ─────────────────────────────
93
- files = []
94
- for idx, item in enumerate(images):
95
- try:
96
- data = item.read() if hasattr(item, "read") else requests.get(item).content
97
- files.append(discord.File(io.BytesIO(data), filename=f"img_{idx}.png"))
98
- except Exception as e:
99
- logging.warning(f"[IMG {idx}] 처리 μ‹€νŒ¨: {e}")
100
-
101
- await message.reply(
102
- files=files if files else None,
103
- content=None if files else "⚠️ 이미지λ₯Ό 전솑할 수 μ—†μŠ΅λ‹ˆλ‹€."
104
- )
 
 
 
 
105
 
106
  # ── μ‹€ν–‰ ────────────────────────────────────────────────────
107
  if __name__ == "__main__":
 
20
  os.environ["REPLICATE_API_TOKEN"] = REPL_TOKEN
21
 
22
  # ── λͺ¨λΈ ────────────────────────────────────────────────────
23
+ MODEL = "luma/ray-flash-2-540p" # ν…μŠ€νŠΈ-투-λΉ„λ””μ˜€ λͺ¨λΈ (540p)
 
 
 
24
 
25
  # ── λ²ˆμ—­ νŒŒμ΄ν”„λΌμΈ (CPU) ───────────────────────────────────
26
  translator_kwargs = {"device": -1}
 
53
  intents = discord.Intents.default()
54
  intents.message_content = True # λ©”μ‹œμ§€ μ½˜ν…μΈ  읽기
55
 
56
+ class ImageBot(discord.Client): # 이름 μœ μ§€
57
  async def on_ready(self):
58
  logging.info(f"Logged in as {self.user} (id={self.user.id})")
59
  # web.py 병렬 μ‹€ν–‰
 
77
 
78
  # ── Replicate 호좜 ──────────────────────────────────
79
  def run_replicate():
80
+ # ν•„μš”ν•œ 경우 input λ”•μ…”λ„ˆλ¦¬μ— duration, seed λ“± μΆ”κ°€ κ°€λŠ₯
81
+ return replicate.run(MODEL, input={"prompt": prompt_en})
82
 
83
  try:
84
+ output = await asyncio.get_running_loop().run_in_executor(None, run_replicate)
85
  except Exception as e:
86
  logging.error(f"Replicate error: {e}")
87
+ await message.reply("⚠️ λΉ„λ””μ˜€ 생성 μ‹€νŒ¨!")
88
  return
89
 
90
+ # ── λΉ„λ””μ˜€ Discord 전솑 ─────────────────────────────
91
+ try:
92
+ # replicate.run κ²°κ³Όκ°€ list/tuple 이면 첫 번째 μš”μ†Œ μ‚¬μš©
93
+ if isinstance(output, (list, tuple)):
94
+ output = output[0]
95
+
96
+ # URL(str) β†’ λ‹€μš΄λ‘œλ“œ, bytes/file-like β†’ κ·ΈλŒ€λ‘œ
97
+ if isinstance(output, str):
98
+ data = requests.get(output).content
99
+ else:
100
+ data = output.read() if hasattr(output, "read") else output
101
+
102
+ video_file = discord.File(io.BytesIO(data), filename="output.mp4")
103
+ await message.reply(files=[video_file])
104
+ except Exception as e:
105
+ logging.warning(f"λΉ„λ””μ˜€ 처리 μ‹€νŒ¨: {e}")
106
+ await message.reply("⚠️ λΉ„λ””μ˜€λ₯Ό 전솑할 수 μ—†μŠ΅λ‹ˆλ‹€.")
107
 
108
  # ── μ‹€ν–‰ ────────────────────────────────────────────────────
109
  if __name__ == "__main__":