ginipick commited on
Commit
356c2dc
Β·
verified Β·
1 Parent(s): 6170788

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -17
app.py CHANGED
@@ -44,20 +44,27 @@ def save_comments(comments):
44
  json.dump(comments, file)
45
 
46
  def download_audio(video_url):
47
- yt = YouTube(video_url)
48
- audio = yt.streams.filter(only_audio=True).first()
49
- audio_path = audio.download(output_path=".")
50
-
51
- file_stats = os.stat(audio_path)
52
- logging.info(f'Size of audio file in Bytes: {file_stats.st_size}')
53
-
54
- if file_stats.st_size <= 30000000: # Check the file size limit
55
- base, ext = os.path.splitext(audio_path)
56
- new_file = base + '.mp3'
57
- os.rename(audio_path, new_file)
58
- return new_file
59
- else:
60
- logging.error('Videos for transcription on this space are limited to about 1.5 hours. Please contact support for more information.')
 
 
 
 
 
 
 
61
  return None
62
 
63
  def generate_transcript(audio_path):
@@ -68,7 +75,7 @@ def generate_transcript(audio_path):
68
  result = model.transcribe(audio_path)
69
  return result['text'].strip()
70
  except Exception as e:
71
- logging.error(f"Exception during transcription: {str(e)}")
72
  return f"전사 쀑 였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€: {str(e)}"
73
 
74
  def generate_reply(comment_text, system_prompt):
@@ -93,7 +100,7 @@ def get_video_comments(video_id):
93
  request = youtube.commentThreads().list(
94
  part='snippet',
95
  videoId=video_id,
96
- maxResults=100, #λŒ“κΈ€ μ½μ–΄λ“€μ΄λŠ” 수 μ •μ˜
97
  textFormat='plainText'
98
  )
99
  response = request.execute()
@@ -113,7 +120,7 @@ def get_video_comments(video_id):
113
  part='snippet',
114
  videoId=video_id,
115
  pageToken=response['nextPageToken'],
116
- maxResults=100, #λŒ“κΈ€ μ½μ–΄λ“€μ΄λŠ” 수 μ •μ˜
117
  textFormat='plainText'
118
  )
119
  response = request.execute()
 
44
  json.dump(comments, file)
45
 
46
  def download_audio(video_url):
47
+ try:
48
+ yt = YouTube(video_url)
49
+ audio = yt.streams.filter(only_audio=True).first()
50
+ if audio is None:
51
+ logging.error('μ˜€λ””μ˜€ μŠ€νŠΈλ¦Όμ„ 찾을 수 μ—†μŠ΅λ‹ˆλ‹€.')
52
+ return None
53
+ audio_path = audio.download(output_path=".")
54
+
55
+ file_stats = os.stat(audio_path)
56
+ logging.info(f'μ˜€λ””μ˜€ 파일 크기(Bytes): {file_stats.st_size}')
57
+
58
+ if file_stats.st_size <= 30000000: # 파일 크기 μ œν•œ 확인
59
+ base, ext = os.path.splitext(audio_path)
60
+ new_file = base + '.mp3'
61
+ os.rename(audio_path, new_file)
62
+ return new_file
63
+ else:
64
+ logging.error('파일 크기가 λ„ˆλ¬΄ ν½λ‹ˆλ‹€. 1.5μ‹œκ°„ μ΄ν•˜μ˜ λΉ„λ””μ˜€λ§Œ μ§€μ›λ©λ‹ˆλ‹€.')
65
+ return None
66
+ except Exception as e:
67
+ logging.error(f"μ˜€λ””μ˜€ λ‹€μš΄λ‘œλ“œ 쀑 였λ₯˜ λ°œμƒ: {str(e)}")
68
  return None
69
 
70
  def generate_transcript(audio_path):
 
75
  result = model.transcribe(audio_path)
76
  return result['text'].strip()
77
  except Exception as e:
78
+ logging.error(f"전사 쀑 였λ₯˜ λ°œμƒ: {str(e)}")
79
  return f"전사 쀑 였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€: {str(e)}"
80
 
81
  def generate_reply(comment_text, system_prompt):
 
100
  request = youtube.commentThreads().list(
101
  part='snippet',
102
  videoId=video_id,
103
+ maxResults=100, # λŒ“κΈ€ μ½μ–΄λ“€μ΄λŠ” 수 μ •μ˜
104
  textFormat='plainText'
105
  )
106
  response = request.execute()
 
120
  part='snippet',
121
  videoId=video_id,
122
  pageToken=response['nextPageToken'],
123
+ maxResults=100, # λŒ“κΈ€ μ½μ–΄λ“€μ΄λŠ” 수 μ •μ˜
124
  textFormat='plainText'
125
  )
126
  response = request.execute()