seawolf2357
commited on
Commit
β’
b1c9665
1
Parent(s):
8a03a11
Update app.py
Browse files
app.py
CHANGED
@@ -21,7 +21,7 @@ hf_client = InferenceClient("CohereForAI/c4ai-command-r-plus", token=os.getenv("
|
|
21 |
|
22 |
# Pexels API ν€ μ€μ
|
23 |
PEXELS_API_KEY = "5woz23MGx1QrSY0WHFb0BRi29JvbXPu97Hg0xnklYgHUI8G0w23FKH62"
|
24 |
-
|
25 |
|
26 |
# νΉμ μ±λ ID
|
27 |
SPECIFIC_CHANNEL_ID = int(os.getenv("DISCORD_CHANNEL_ID"))
|
@@ -42,7 +42,7 @@ class MyClient(discord.Client):
|
|
42 |
# λ΄μ΄ μμλ λ μλ΄ λ©μμ§λ₯Ό μ μ‘
|
43 |
channel = self.get_channel(SPECIFIC_CHANNEL_ID)
|
44 |
if channel:
|
45 |
-
await channel.send("μ°Ύκ³ μΆμ
|
46 |
|
47 |
async def on_message(self, message):
|
48 |
if message.author == self.user:
|
@@ -56,13 +56,13 @@ class MyClient(discord.Client):
|
|
56 |
# μλ―Έ λΆμνμ¬ μλ¬Έ ν€μλ μΆμΆ
|
57 |
keywords = await extract_keywords(message)
|
58 |
if keywords:
|
59 |
-
# Pexels APIλ‘
|
60 |
-
|
61 |
-
if
|
62 |
-
# μμ²μμμ μ°λ λ μμ± λ°
|
63 |
-
await
|
64 |
else:
|
65 |
-
await message.channel.send(f"**{keywords}**μ λν
|
66 |
else:
|
67 |
await message.channel.send("ν€μλλ₯Ό μΆμΆν μ μμ΅λλ€.")
|
68 |
finally:
|
@@ -95,26 +95,26 @@ async def extract_keywords(message):
|
|
95 |
logging.debug(f'Extracted keywords: {keywords}')
|
96 |
return keywords
|
97 |
|
98 |
-
async def
|
99 |
headers = {
|
100 |
"Authorization": PEXELS_API_KEY
|
101 |
}
|
102 |
params = {
|
103 |
"query": keywords,
|
104 |
-
"per_page": 80 # μ΅λ 20κ°
|
105 |
}
|
106 |
-
response = requests.get(
|
107 |
if response.status_code == 200:
|
108 |
data = response.json()
|
109 |
-
return [
|
110 |
return None
|
111 |
|
112 |
-
async def
|
113 |
# μ°λ λ μμ±
|
114 |
thread = await message.channel.create_thread(name=f"{message.author.name}μ κ²μ κ²°κ³Ό", message=message)
|
115 |
-
message_content = f"**{keywords}**μ λν
|
116 |
await thread.send(message_content)
|
117 |
-
for url in
|
118 |
await thread.send(url)
|
119 |
|
120 |
if __name__ == "__main__":
|
|
|
21 |
|
22 |
# Pexels API ν€ μ€μ
|
23 |
PEXELS_API_KEY = "5woz23MGx1QrSY0WHFb0BRi29JvbXPu97Hg0xnklYgHUI8G0w23FKH62"
|
24 |
+
PEXELS_API_VIDEO_URL = "https://api.pexels.com/videos/search"
|
25 |
|
26 |
# νΉμ μ±λ ID
|
27 |
SPECIFIC_CHANNEL_ID = int(os.getenv("DISCORD_CHANNEL_ID"))
|
|
|
42 |
# λ΄μ΄ μμλ λ μλ΄ λ©μμ§λ₯Ό μ μ‘
|
43 |
channel = self.get_channel(SPECIFIC_CHANNEL_ID)
|
44 |
if channel:
|
45 |
+
await channel.send("μ°Ύκ³ μΆμ λμμμ λν μ€λͺ
μ ν λ¬Έμ₯ λ¨μλ‘ μ
λ ₯νμΈμ. μ) λλ°μμ λ°μ΄ λ
Έλ κ°μμ§")
|
46 |
|
47 |
async def on_message(self, message):
|
48 |
if message.author == self.user:
|
|
|
56 |
# μλ―Έ λΆμνμ¬ μλ¬Έ ν€μλ μΆμΆ
|
57 |
keywords = await extract_keywords(message)
|
58 |
if keywords:
|
59 |
+
# Pexels APIλ‘ λμμ κ²μ
|
60 |
+
video_urls = await search_videos(keywords)
|
61 |
+
if video_urls:
|
62 |
+
# μμ²μμμ μ°λ λ μμ± λ° λμμ μ μ‘
|
63 |
+
await create_thread_and_send_videos(message, keywords, video_urls)
|
64 |
else:
|
65 |
+
await message.channel.send(f"**{keywords}**μ λν λμμμ μ°Ύμ μ μμ΅λλ€.")
|
66 |
else:
|
67 |
await message.channel.send("ν€μλλ₯Ό μΆμΆν μ μμ΅λλ€.")
|
68 |
finally:
|
|
|
95 |
logging.debug(f'Extracted keywords: {keywords}')
|
96 |
return keywords
|
97 |
|
98 |
+
async def search_videos(keywords):
|
99 |
headers = {
|
100 |
"Authorization": PEXELS_API_KEY
|
101 |
}
|
102 |
params = {
|
103 |
"query": keywords,
|
104 |
+
"per_page": 80 # μ΅λ 20κ° λμμμ κ°μ Έμ΅λλ€
|
105 |
}
|
106 |
+
response = requests.get(PEXELS_API_VIDEO_URL, headers=headers, params=params)
|
107 |
if response.status_code == 200:
|
108 |
data = response.json()
|
109 |
+
return [video['video_files'][0]['link'] for video in data['videos']]
|
110 |
return None
|
111 |
|
112 |
+
async def create_thread_and_send_videos(message, keywords, video_urls):
|
113 |
# μ°λ λ μμ±
|
114 |
thread = await message.channel.create_thread(name=f"{message.author.name}μ κ²μ κ²°κ³Ό", message=message)
|
115 |
+
message_content = f"**{keywords}**μ λν λμμ {len(video_urls)}κ°λ₯Ό μ°Ύμμ΅λλ€:"
|
116 |
await thread.send(message_content)
|
117 |
+
for url in video_urls:
|
118 |
await thread.send(url)
|
119 |
|
120 |
if __name__ == "__main__":
|