Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -15,6 +15,7 @@ intents.message_content = True
|
|
15 |
intents.messages = True
|
16 |
intents.guilds = True
|
17 |
intents.guild_messages = True
|
|
|
18 |
|
19 |
# ์ถ๋ก API ํด๋ผ์ด์ธํธ ์ค์
|
20 |
hf_client = InferenceClient("CohereForAI/c4ai-command-r-plus", token=os.getenv("HF_TOKEN"))
|
@@ -57,10 +58,10 @@ class MyClient(discord.Client):
|
|
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:
|
@@ -106,31 +107,16 @@ async def search_images(keywords):
|
|
106 |
response = requests.get(PEXELS_API_URL, headers=headers, params=params)
|
107 |
if response.status_code == 200:
|
108 |
data = response.json()
|
109 |
-
return [
|
110 |
-
"url": photo['src']['large2x'],
|
111 |
-
"thumbnail": photo['src']['medium'], # ์ธ๋ค์ผ์ medium ์ฌ์ด์ฆ๋ก ์ฌ์ฉ
|
112 |
-
"title": photo['alt']
|
113 |
-
} for photo in data['photos']]
|
114 |
return None
|
115 |
|
116 |
-
async def
|
117 |
-
|
118 |
-
await channel.
|
119 |
-
|
120 |
-
|
121 |
-
for
|
122 |
-
|
123 |
-
embed.set_thumbnail(url=info["thumbnail"])
|
124 |
-
embeds.append(embed)
|
125 |
-
|
126 |
-
# ๋์ค์ฝ๋ ์๋ฒ ๋ ๋ฉ์์ง๋ ํ ๋ฒ์ ์ต๋ 10๊ฐ๊น์ง ๋ณด๋ด๋ฏ๋ก ํ ๋ฒ์ ๋ณด๋ด๊ธฐ
|
127 |
-
if len(embeds) == 10:
|
128 |
-
await channel.send(embeds=embeds)
|
129 |
-
embeds = []
|
130 |
-
|
131 |
-
# ๋จ์ ์๋ฒ ๋ ์ ์ก
|
132 |
-
if embeds:
|
133 |
-
await channel.send(embeds=embeds)
|
134 |
|
135 |
if __name__ == "__main__":
|
136 |
discord_client = MyClient(intents=intents)
|
|
|
15 |
intents.messages = True
|
16 |
intents.guilds = True
|
17 |
intents.guild_messages = True
|
18 |
+
intents.threads = True # ์ค๋ ๋ ๊ถํ ์ถ๊ฐ
|
19 |
|
20 |
# ์ถ๋ก API ํด๋ผ์ด์ธํธ ์ค์
|
21 |
hf_client = InferenceClient("CohereForAI/c4ai-command-r-plus", token=os.getenv("HF_TOKEN"))
|
|
|
58 |
keywords = await extract_keywords(message)
|
59 |
if keywords:
|
60 |
# Pexels API๋ก ๊ณ ํด์๋ ์ด๋ฏธ์ง ๊ฒ์
|
61 |
+
image_urls = await search_images(keywords)
|
62 |
+
if image_urls:
|
63 |
+
# ์์ฒญ์์์ ์ฐ๋ ๋ ์์ฑ ๋ฐ ๊ณ ํด์๋ ์ด๋ฏธ์ง ์ ์ก
|
64 |
+
await create_thread_and_send_images(message, keywords, image_urls)
|
65 |
else:
|
66 |
await message.channel.send(f"**{keywords}**์ ๋ํ ๊ณ ํด์๋ ์ด๋ฏธ์ง๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค.")
|
67 |
else:
|
|
|
107 |
response = requests.get(PEXELS_API_URL, headers=headers, params=params)
|
108 |
if response.status_code == 200:
|
109 |
data = response.json()
|
110 |
+
return [photo['src']['large2x'] for photo in data['photos']]
|
|
|
|
|
|
|
|
|
111 |
return None
|
112 |
|
113 |
+
async def create_thread_and_send_images(message, keywords, image_urls):
|
114 |
+
# ์ฐ๋ ๋ ์์ฑ
|
115 |
+
thread = await message.channel.create_thread(name=f"{message.author.name}์ ๊ฒ์ ๊ฒฐ๊ณผ", message=message)
|
116 |
+
message_content = f"**{keywords}**์ ๋ํ ๊ณ ํด์๋ ์ด๋ฏธ์ง {len(image_urls)}์ฅ์ ์ฐพ์์ต๋๋ค:"
|
117 |
+
await thread.send(message_content)
|
118 |
+
for url in image_urls:
|
119 |
+
await thread.send(url)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
120 |
|
121 |
if __name__ == "__main__":
|
122 |
discord_client = MyClient(intents=intents)
|