seawolf2357
commited on
Commit
โข
6a13d8f
1
Parent(s):
cf850ea
Update app.py
Browse files
app.py
CHANGED
@@ -4,6 +4,7 @@ import os
|
|
4 |
import re
|
5 |
import asyncio
|
6 |
import json
|
|
|
7 |
from huggingface_hub import InferenceClient
|
8 |
from googleapiclient.discovery import build
|
9 |
from google.oauth2.credentials import Credentials
|
@@ -16,11 +17,9 @@ from dotenv import load_dotenv
|
|
16 |
# ํ๊ฒฝ ๋ณ์ ๋ก๋
|
17 |
load_dotenv()
|
18 |
|
19 |
-
# JSON_TOKEN
|
20 |
-
|
21 |
-
|
22 |
-
with open(credentials_path, 'w') as f:
|
23 |
-
f.write(json_token)
|
24 |
|
25 |
# ๋ก๊น
์ค์
|
26 |
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s:%(levelname)s:%(name)s:%(message)s', handlers=[logging.StreamHandler()])
|
@@ -35,21 +34,19 @@ intents.guild_messages = True
|
|
35 |
# ์ถ๋ก API ํด๋ผ์ด์ธํธ ์ค์
|
36 |
hf_client = InferenceClient("CohereForAI/c4ai-command-r-plus", token=os.getenv("HF_TOKEN"))
|
37 |
|
38 |
-
#
|
39 |
SCOPES = ["https://www.googleapis.com/auth/youtube.force-ssl"]
|
40 |
-
TOKEN_PATH = 'token.json'
|
41 |
creds = None
|
42 |
|
43 |
-
if os.path.exists(
|
44 |
-
creds = Credentials.from_authorized_user_file(
|
45 |
if not creds or not creds.valid:
|
46 |
if creds and creds.expired and creds.refresh_token:
|
47 |
creds.refresh(Request())
|
48 |
else:
|
49 |
-
flow = InstalledAppFlow.from_client_secrets_file(
|
50 |
-
credentials_path, SCOPES)
|
51 |
creds = flow.run_local_server(port=0)
|
52 |
-
with open(
|
53 |
token.write(creds.to_json())
|
54 |
|
55 |
youtube_service = build('youtube', 'v3', credentials=creds)
|
@@ -65,6 +62,10 @@ class MyClient(discord.Client):
|
|
65 |
async def on_ready(self):
|
66 |
logging.info(f'{self.user}๋ก ๋ก๊ทธ์ธ๋์์ต๋๋ค!')
|
67 |
|
|
|
|
|
|
|
|
|
68 |
# ๋ด์ด ์์๋ ๋ ์๋ด ๋ฉ์์ง๋ฅผ ์ ์ก
|
69 |
channel = self.get_channel(SPECIFIC_CHANNEL_ID)
|
70 |
if channel:
|
@@ -175,7 +176,7 @@ async def generate_replies(comments, transcript):
|
|
175 |
]
|
176 |
loop = asyncio.get_event_loop()
|
177 |
response = await loop.run_in_executor(None, lambda: hf_client.chat_completion(
|
178 |
-
messages, max_tokens=
|
179 |
|
180 |
if response.choices and response.choices[0].message:
|
181 |
reply = response.choices[0].message['content'].strip()
|
|
|
4 |
import re
|
5 |
import asyncio
|
6 |
import json
|
7 |
+
import subprocess
|
8 |
from huggingface_hub import InferenceClient
|
9 |
from googleapiclient.discovery import build
|
10 |
from google.oauth2.credentials import Credentials
|
|
|
17 |
# ํ๊ฒฝ ๋ณ์ ๋ก๋
|
18 |
load_dotenv()
|
19 |
|
20 |
+
# JSON_TOKEN.json ํ์ผ์ ๊ฒฝ๋ก
|
21 |
+
credentials_path = 'JSON_TOKEN.json'
|
22 |
+
token_path = 'token.json'
|
|
|
|
|
23 |
|
24 |
# ๋ก๊น
์ค์
|
25 |
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s:%(levelname)s:%(name)s:%(message)s', handlers=[logging.StreamHandler()])
|
|
|
34 |
# ์ถ๋ก API ํด๋ผ์ด์ธํธ ์ค์
|
35 |
hf_client = InferenceClient("CohereForAI/c4ai-command-r-plus", token=os.getenv("HF_TOKEN"))
|
36 |
|
37 |
+
# OAuth 2.0 ์ธ์ฆ ์ค์
|
38 |
SCOPES = ["https://www.googleapis.com/auth/youtube.force-ssl"]
|
|
|
39 |
creds = None
|
40 |
|
41 |
+
if os.path.exists(token_path):
|
42 |
+
creds = Credentials.from_authorized_user_file(token_path, SCOPES)
|
43 |
if not creds or not creds.valid:
|
44 |
if creds and creds.expired and creds.refresh_token:
|
45 |
creds.refresh(Request())
|
46 |
else:
|
47 |
+
flow = InstalledAppFlow.from_client_secrets_file(credentials_path, SCOPES)
|
|
|
48 |
creds = flow.run_local_server(port=0)
|
49 |
+
with open(token_path, 'w') as token:
|
50 |
token.write(creds.to_json())
|
51 |
|
52 |
youtube_service = build('youtube', 'v3', credentials=creds)
|
|
|
62 |
async def on_ready(self):
|
63 |
logging.info(f'{self.user}๋ก ๋ก๊ทธ์ธ๋์์ต๋๋ค!')
|
64 |
|
65 |
+
# web.py ํ์ผ ์คํ
|
66 |
+
subprocess.Popen(["python", "web.py"])
|
67 |
+
logging.info("Web.py server has been started.")
|
68 |
+
|
69 |
# ๋ด์ด ์์๋ ๋ ์๋ด ๋ฉ์์ง๋ฅผ ์ ์ก
|
70 |
channel = self.get_channel(SPECIFIC_CHANNEL_ID)
|
71 |
if channel:
|
|
|
176 |
]
|
177 |
loop = asyncio.get_event_loop()
|
178 |
response = await loop.run_in_executor(None, lambda: hf_client.chat_completion(
|
179 |
+
messages, max_tokens=400, temperature=0.7, top_p=0.85)) # max_tokens ๊ฐ์ ์กฐ์
|
180 |
|
181 |
if response.choices and response.choices[0].message:
|
182 |
reply = response.choices[0].message['content'].strip()
|