Update app.py
Browse files
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 |
-
|
|
|
|
| 84 |
|
| 85 |
try:
|
| 86 |
-
|
| 87 |
except Exception as e:
|
| 88 |
logging.error(f"Replicate error: {e}")
|
| 89 |
-
await message.reply("β οΈ
|
| 90 |
return
|
| 91 |
|
| 92 |
-
# ββ
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 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__":
|