AIRider commited on
Commit
a7e5781
ยท
verified ยท
1 Parent(s): 628acdb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -31
app.py CHANGED
@@ -87,20 +87,45 @@ def summarize_text(title, description, text):
87
  """
88
  return call_api(prompt, max_tokens=8000, temperature=0.35, top_p=0.95)
89
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
  def analyze(url, progress=gr.Progress()):
91
  try:
92
  progress(0, desc="์Šคํฌ๋ฆฝํŠธ ์ถ”์ถœ ์ค‘...")
93
  title, description, script = get_youtube_script(url)
94
 
95
  progress(0.25, desc="์›๋ฌธ ์Šคํฌ๋ฆฝํŠธ ์ฒ˜๋ฆฌ ์ค‘...")
96
- script_sentences = split_sentences(script)
97
- script_content = f"# {title}\n\n" + "\n".join(script_sentences)
98
 
99
  # ์›๋ฌธ ์Šคํฌ๋ฆฝํŠธ ๋จผ์ € ์ถœ๋ ฅํ•˜๊ณ  ์ง„ํ–‰
100
  yield script_content, "์š”์•ฝ ์ค€๋น„ ์ค‘..."
101
 
102
  progress(0.5, desc="์š”์•ฝ ์ƒ์„ฑ ์ค‘...")
103
- summary = summarize_text(title, description, "\n".join(script_sentences))
104
 
105
  progress(0.75, desc="์š”์•ฝ ๋‚ด์šฉ ์ •๋ฆฌ ์ค‘...")
106
  summary_content = f"# {title}\n\n{summary}"
@@ -112,34 +137,6 @@ def analyze(url, progress=gr.Progress()):
112
  logging.exception(error_msg)
113
  yield error_msg, error_msg
114
 
115
- def split_sentences(text):
116
- sentence_end = r'(๋‹ˆ๋‹ค|์—์š”|๊ตฌ๋‚˜|ํ•ด์š”|๊ตฐ์š”|๊ฒ ์–ด์š”|์‹œ์˜ค|ํ•ด๋ผ|์˜ˆ์š”|์•„์š”|๋ฐ์š”|๋Œ€์š”|์„ธ์š”|์–ด์š”|๊ฒŒ์š”|๊ตฌ์š”|๊ณ ์š”|๋‚˜์š”|ํ•˜์ฃ )(?![\w])'
117
- segments = re.split(f'({sentence_end})', text)
118
-
119
- combined_sentences = []
120
- current_sentence = ""
121
-
122
- for i in range(0, len(segments), 2):
123
- segment = segments[i]
124
- if i + 1 < len(segments):
125
- segment += segments[i + 1]
126
-
127
- if len(current_sentence) + len(segment) > 100:
128
- if current_sentence:
129
- combined_sentences.append(current_sentence.strip())
130
- current_sentence = segment.strip()
131
- else:
132
- current_sentence += (' ' if current_sentence else '') + segment.strip()
133
-
134
- if re.search(sentence_end, segment):
135
- combined_sentences.append(current_sentence.strip())
136
- current_sentence = ""
137
-
138
- if current_sentence:
139
- combined_sentences.append(current_sentence.strip())
140
-
141
- return combined_sentences
142
-
143
  # Gradio ์ธํ„ฐํŽ˜์ด์Šค
144
  with gr.Blocks() as demo:
145
  gr.Markdown("## YouTube ์Šคํฌ๋ฆฝํŠธ ์ถ”์ถœ ๋ฐ ์š”์•ฝ ๋„๊ตฌ")
 
87
  """
88
  return call_api(prompt, max_tokens=8000, temperature=0.35, top_p=0.95)
89
 
90
+ def split_sentences(text):
91
+ sentences = re.split(r"(๋‹ˆ๋‹ค|์—์š”|๊ตฌ๋‚˜|ํ•ด์š”|๊ตฐ์š”|๊ฒ ์–ด์š”|์‹œ์˜ค|ํ•ด๋ผ|์˜ˆ์š”|์•„์š”|๋ฐ์š”|๋Œ€์š”|์„ธ์š”|์–ด์š”|๊ฒŒ์š”|๊ตฌ์š”|๊ณ ์š”|๋‚˜์š”|ํ•˜์ฃ )(?![\w])", text)
92
+ combined_sentences = []
93
+ current_sentence = ""
94
+ for i in range(0, len(sentences), 2):
95
+ if i + 1 < len(sentences):
96
+ sentence = sentences[i] + sentences[i + 1]
97
+ else:
98
+ sentence = sentences[i]
99
+ if len(current_sentence) + len(sentence) > 100: # 100์ž๋ฅผ ์ดˆ๊ณผํ•  ๊ฒฝ์šฐ
100
+ combined_sentences.append(current_sentence.strip())
101
+ current_sentence = sentence.strip()
102
+ else:
103
+ current_sentence += sentence
104
+ if sentence.endswith(('.', '?', '!')):
105
+ combined_sentences.append(current_sentence.strip())
106
+ current_sentence = ""
107
+ if current_sentence:
108
+ combined_sentences.append(current_sentence.strip())
109
+ return combined_sentences
110
+
111
+ def display_script(title, script):
112
+ script_sentences = split_sentences(script)
113
+ formatted_script = "\n\n".join(script_sentences)
114
+ return f"# {title}\n\n{formatted_script}"
115
+
116
  def analyze(url, progress=gr.Progress()):
117
  try:
118
  progress(0, desc="์Šคํฌ๋ฆฝํŠธ ์ถ”์ถœ ์ค‘...")
119
  title, description, script = get_youtube_script(url)
120
 
121
  progress(0.25, desc="์›๋ฌธ ์Šคํฌ๋ฆฝํŠธ ์ฒ˜๋ฆฌ ์ค‘...")
122
+ script_content = display_script(title, script)
 
123
 
124
  # ์›๋ฌธ ์Šคํฌ๋ฆฝํŠธ ๋จผ์ € ์ถœ๋ ฅํ•˜๊ณ  ์ง„ํ–‰
125
  yield script_content, "์š”์•ฝ ์ค€๋น„ ์ค‘..."
126
 
127
  progress(0.5, desc="์š”์•ฝ ์ƒ์„ฑ ์ค‘...")
128
+ summary = summarize_text(title, description, script)
129
 
130
  progress(0.75, desc="์š”์•ฝ ๋‚ด์šฉ ์ •๋ฆฌ ์ค‘...")
131
  summary_content = f"# {title}\n\n{summary}"
 
137
  logging.exception(error_msg)
138
  yield error_msg, error_msg
139
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
  # Gradio ์ธํ„ฐํŽ˜์ด์Šค
141
  with gr.Blocks() as demo:
142
  gr.Markdown("## YouTube ์Šคํฌ๋ฆฝํŠธ ์ถ”์ถœ ๋ฐ ์š”์•ฝ ๋„๊ตฌ")