seawolf2357 commited on
Commit
a5439b2
โ€ข
1 Parent(s): bece13e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -7
app.py CHANGED
@@ -3,6 +3,7 @@ import logging
3
  import os
4
  import re
5
  import asyncio
 
6
  from huggingface_hub import InferenceClient
7
  from googleapiclient.discovery import build
8
  from google.oauth2.credentials import Credentials
@@ -15,6 +16,12 @@ from dotenv import load_dotenv
15
  # ํ™˜๊ฒฝ ๋ณ€์ˆ˜ ๋กœ๋“œ
16
  load_dotenv()
17
 
 
 
 
 
 
 
18
  # ๋กœ๊น… ์„ค์ •
19
  logging.basicConfig(level=logging.DEBUG, format='%(asctime)s:%(levelname)s:%(name)s:%(message)s', handlers=[logging.StreamHandler()])
20
 
@@ -29,13 +36,9 @@ intents.guild_messages = True
29
  hf_client = InferenceClient("CohereForAI/c4ai-command-r-plus", token=os.getenv("HF_TOKEN"))
30
 
31
  # YouTube API ํ‚ค ์„ค์ • ๋ฐ OAuth 2.0 ์ธ์ฆ ์„ค์ •
32
- YOUTUBE_API_KEY = os.getenv("YOUTUBE_API_KEY")
33
  SCOPES = ["https://www.googleapis.com/auth/youtube.force-ssl"]
34
- creds = None
35
-
36
- # ํ™˜๊ฒฝ๋ณ€์ˆ˜ ์„ค์ • (ํ† ํฐ์„ ์ €์žฅํ•  ํŒŒ์ผ ๊ฒฝ๋กœ)
37
  TOKEN_PATH = 'token.json'
38
- CREDENTIALS_PATH = 'credentials.json'
39
 
40
  if os.path.exists(TOKEN_PATH):
41
  creds = Credentials.from_authorized_user_file(TOKEN_PATH, SCOPES)
@@ -44,7 +47,7 @@ if not creds or not creds.valid:
44
  creds.refresh(Request())
45
  else:
46
  flow = InstalledAppFlow.from_client_secrets_file(
47
- 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())
@@ -172,7 +175,7 @@ async def generate_replies(comments, transcript):
172
  ]
173
  loop = asyncio.get_event_loop()
174
  response = await loop.run_in_executor(None, lambda: hf_client.chat_completion(
175
- messages, max_tokens=400, temperature=0.7, top_p=0.85)) # max_tokens ๊ฐ’์„ ์กฐ์ •
176
 
177
  if response.choices and response.choices[0].message:
178
  reply = response.choices[0].message['content'].strip()
 
3
  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
  # ํ™˜๊ฒฝ ๋ณ€์ˆ˜ ๋กœ๋“œ
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()])
27
 
 
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)
 
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())
 
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()