AIRider commited on
Commit
0300f5a
Β·
verified Β·
1 Parent(s): ca80bc7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -5
app.py CHANGED
@@ -14,8 +14,25 @@ openai.api_key = os.getenv("OPENAI_API_KEY")
14
 
15
  # λ¬Έμž₯ ꡬ뢄 ν•¨μˆ˜
16
  def split_sentences(text):
17
- sentences = re.split(r'([.!?]+)\s*', text)
18
- return ''.join(sentences).split()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
  def parse_api_response(response):
21
  try:
@@ -99,13 +116,15 @@ def analyze(url, progress=gr.Progress()):
99
 
100
  progress(33, desc="원문 슀크립트 처리 쀑...")
101
  script_sentences = split_sentences(script)
102
- script_content = f"# {title}\n\n" + "\n".join([s + "." for s in script_sentences])
103
 
104
- progress(0.66, desc="μš”μ•½ 생성 쀑...")
105
  summary = summarize_text(title, description, script)
 
 
106
  summary_content = f"# {title}\n\n{summary}"
107
 
108
- progress(1.0, desc="μ™„λ£Œ")
109
  return script_content, summary_content
110
  except Exception as e:
111
  error_msg = f"처리 쀑 였λ₯˜ λ°œμƒ: {str(e)}"
 
14
 
15
  # λ¬Έμž₯ ꡬ뢄 ν•¨μˆ˜
16
  def split_sentences(text):
17
+ sentences = re.split(r"(λ‹ˆλ‹€|μ—μš”|κ΅¬λ‚˜|ν•΄μš”|κ΅°μš”|κ² μ–΄μš”|μ‹œμ˜€|해라|μ˜ˆμš”|μ•„μš”|λ°μš”|λŒ€μš”|μ„Έμš”|μ–΄μš”|κ²Œμš”|κ΅¬μš”|κ³ μš”|λ‚˜μš”|ν•˜μ£ )(?![\w])", text)
18
+ combined_sentences = []
19
+ current_sentence = ""
20
+ for i in range(0, len(sentences), 2):
21
+ if i + 1 < len(sentences):
22
+ sentence = sentences[i] + sentences[i + 1]
23
+ else:
24
+ sentence = sentences[i]
25
+ if len(current_sentence) + len(sentence) > 100: # 100자λ₯Ό μ΄ˆκ³Όν•  경우
26
+ combined_sentences.append(current_sentence.strip())
27
+ current_sentence = sentence.strip()
28
+ else:
29
+ current_sentence += sentence
30
+ if sentence.endswith(('.', '?', '!')):
31
+ combined_sentences.append(current_sentence.strip())
32
+ current_sentence = ""
33
+ if current_sentence:
34
+ combined_sentences.append(current_sentence.strip())
35
+ return combined_sentences
36
 
37
  def parse_api_response(response):
38
  try:
 
116
 
117
  progress(33, desc="원문 슀크립트 처리 쀑...")
118
  script_sentences = split_sentences(script)
119
+ script_content = f"# {title}\n\n" + "\n".join(script_sentences)
120
 
121
+ progress(66, desc="μš”μ•½ 생성 쀑...")
122
  summary = summarize_text(title, description, script)
123
+
124
+ progress(88, desc="μš”μ•½ λ‚΄μš© 정리 쀑...")
125
  summary_content = f"# {title}\n\n{summary}"
126
 
127
+ progress(100, desc="μ™„λ£Œ")
128
  return script_content, summary_content
129
  except Exception as e:
130
  error_msg = f"처리 쀑 였λ₯˜ λ°œμƒ: {str(e)}"