Spaces:
Runtime error
Runtime error
seawolf2357
commited on
Commit
β’
11fec5e
1
Parent(s):
262fbfb
Update app.py
Browse files
app.py
CHANGED
@@ -40,6 +40,71 @@ WEBHOOK_URL = "https://connect.pabbly.com/workflow/sendwebhookdata/IjU3NjUwNTY1M
|
|
40 |
# μ μ‘ μ€ν¨ μ μ¬μλ νμ
|
41 |
MAX_RETRIES = 3
|
42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
class MyClient(discord.Client):
|
44 |
def __init__(self, *args, **kwargs):
|
45 |
super().__init__(*args, **kwargs)
|
@@ -192,7 +257,7 @@ async def create_thread_and_send_replies(message, video_id, comments, replies, s
|
|
192 |
webhook_data["replies"].append({"comment": comment, "reply": reply, "comment_id": comment_id})
|
193 |
|
194 |
# λ°μ΄ν°λ₯Ό μ¬λ¬ λ² λλμ΄ μ μ‘
|
195 |
-
chunk_size =
|
196 |
for i in range(0, len(webhook_data["replies"]), chunk_size):
|
197 |
chunk = webhook_data["replies"][i:i+chunk_size]
|
198 |
chunk_data = {"video_id": video_id, "replies": chunk}
|
|
|
40 |
# μ μ‘ μ€ν¨ μ μ¬μλ νμ
|
41 |
MAX_RETRIES = 3
|
42 |
|
43 |
+
class MyClient(discord.Client):
|
44 |
+
def __init__(self, *args, **kwargs):
|
45 |
+
super().__init__(*args, **kwargs)
|
46 |
+
self.is_processing = False
|
47 |
+
self.session = None
|
48 |
+
|
49 |
+
async def on_ready(self):
|
50 |
+
logging.info(f'{self.user}λ‘ λ‘κ·ΈμΈλμμ΅λλ€!')
|
51 |
+
|
52 |
+
# web.py νμΌ μ€ν
|
53 |
+
subprocess.Popen(["python", "web.py"])
|
54 |
+
logging.info("Web.py μλ²κ° μμλμμ΅λλ€.")
|
55 |
+
|
56 |
+
# aiohttp ν΄λΌμ΄μΈνΈ μΈμ
μμ±
|
57 |
+
self.session = aiohttp.ClientSession()
|
58 |
+
|
59 |
+
# λ΄μ΄ μμλ λ μλ΄ λ©μμ§λ₯Ό μ μ‘
|
60 |
+
channel = self.get_channel(SPECIFIC_CHANNEL_ID)
|
61 |
+
if channel:
|
62 |
+
await channel.send("μ νλΈ λΉλμ€ URLμ μ
λ ₯νλ©΄, μλ§κ³Ό λκΈμ κΈ°λ°μΌλ‘ λ΅κΈμ μμ±ν©λλ€.")
|
63 |
+
|
64 |
+
async def on_message(self, message):
|
65 |
+
if message.author == self.user:
|
66 |
+
returnimport discord
|
67 |
+
import logging
|
68 |
+
import os
|
69 |
+
import re
|
70 |
+
import asyncio
|
71 |
+
import subprocess
|
72 |
+
import aiohttp
|
73 |
+
from huggingface_hub import InferenceClient
|
74 |
+
from googleapiclient.discovery import build
|
75 |
+
from youtube_transcript_api import YouTubeTranscriptApi
|
76 |
+
from youtube_transcript_api.formatters import TextFormatter
|
77 |
+
from dotenv import load_dotenv
|
78 |
+
|
79 |
+
# νκ²½ λ³μ λ‘λ
|
80 |
+
load_dotenv()
|
81 |
+
|
82 |
+
# λ‘κΉ
μ€μ
|
83 |
+
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s:%(levelname)s:%(name)s:%(message)s', handlers=[logging.StreamHandler()])
|
84 |
+
|
85 |
+
# μΈν
νΈ μ€μ
|
86 |
+
intents = discord.Intents.default()
|
87 |
+
intents.message_content = True
|
88 |
+
intents.messages = True
|
89 |
+
intents.guilds = True
|
90 |
+
intents.guild_messages = True
|
91 |
+
|
92 |
+
# μΆλ‘ API ν΄λΌμ΄μΈνΈ μ€μ
|
93 |
+
hf_client = InferenceClient("CohereForAI/c4ai-command-r-plus", token=os.getenv("HF_TOKEN"))
|
94 |
+
|
95 |
+
# YouTube API μ€μ
|
96 |
+
API_KEY = os.getenv("YOUTUBE_API_KEY")
|
97 |
+
youtube_service = build('youtube', 'v3', developerKey=API_KEY)
|
98 |
+
|
99 |
+
# νΉμ μ±λ ID
|
100 |
+
SPECIFIC_CHANNEL_ID = int(os.getenv("DISCORD_CHANNEL_ID"))
|
101 |
+
|
102 |
+
# μΉν
URL μ€μ
|
103 |
+
WEBHOOK_URL = "https://connect.pabbly.com/workflow/sendwebhookdata/IjU3NjUwNTY1MDYzMjA0MzA1MjY4NTUzMDUxMzUi_pc"
|
104 |
+
|
105 |
+
# μ μ‘ μ€ν¨ μ μ¬μλ νμ
|
106 |
+
MAX_RETRIES = 3
|
107 |
+
|
108 |
class MyClient(discord.Client):
|
109 |
def __init__(self, *args, **kwargs):
|
110 |
super().__init__(*args, **kwargs)
|
|
|
257 |
webhook_data["replies"].append({"comment": comment, "reply": reply, "comment_id": comment_id})
|
258 |
|
259 |
# λ°μ΄ν°λ₯Ό μ¬λ¬ λ² λλμ΄ μ μ‘
|
260 |
+
chunk_size = 1 # μ μ‘ν λ°μ΄ν°μ κ°μλ₯Ό 1λ‘ μ€μ νμ¬ κ° λ°μ΄ν°λ₯Ό λ³λλ‘ μ μ‘
|
261 |
for i in range(0, len(webhook_data["replies"]), chunk_size):
|
262 |
chunk = webhook_data["replies"][i:i+chunk_size]
|
263 |
chunk_data = {"video_id": video_id, "replies": chunk}
|