Spaces:
Runtime error
Runtime error
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()
|