seawolf2357 commited on
Commit
6a13d8f
โ€ข
1 Parent(s): cf850ea

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -13
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 ํ™˜๊ฒฝ ๋ณ€์ˆ˜์—์„œ credentials.json ๋‚ด์šฉ์„ ์ฝ์–ด ํŒŒ์ผ๋กœ ์ €์žฅ
20
- json_token = os.getenv('JSON_TOKEN')
21
- credentials_path = 'credentials.json'
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
- # YouTube API ํ‚ค ์„ค์ • ๋ฐ OAuth 2.0 ์ธ์ฆ ์„ค์ •
39
  SCOPES = ["https://www.googleapis.com/auth/youtube.force-ssl"]
40
- TOKEN_PATH = 'token.json'
41
  creds = None
42
 
43
- if os.path.exists(TOKEN_PATH):
44
- creds = Credentials.from_authorized_user_file(TOKEN_PATH, SCOPES)
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(TOKEN_PATH, 'w') as token:
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=100, temperature=0.7, top_p=0.85)) # 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()