AIRider commited on
Commit
201c5c9
ยท
verified ยท
1 Parent(s): 165681a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -25
app.py CHANGED
@@ -14,25 +14,8 @@ openai.api_key = os.getenv("OPENAI_API_KEY")
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,17 +99,18 @@ def analyze(url, progress=gr.Progress()):
116
 
117
  progress(33, desc="์›๋ฌธ ์Šคํฌ๋ฆฝํŠธ ์ฒ˜๋ฆฌ ์ค‘...")
118
  script_sentences = split_sentences(script)
119
- script_content = "\n".join(script_sentences)
120
 
121
  progress(66, desc="์š”์•ฝ ์ƒ์„ฑ ์ค‘...")
122
  summary = summarize_text(title, description, script)
 
123
 
124
  progress(100, desc="์™„๋ฃŒ")
125
- return title, script_content, summary
126
  except Exception as e:
127
  error_msg = f"์ฒ˜๋ฆฌ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ: {str(e)}"
128
  logging.exception(error_msg)
129
- return "์˜ค๋ฅ˜ ๋ฐœ์ƒ", error_msg, error_msg
130
 
131
  # Gradio ์ธํ„ฐํŽ˜์ด์Šค
132
  with gr.Blocks() as demo:
@@ -134,8 +118,6 @@ with gr.Blocks() as demo:
134
  youtube_url_input = gr.Textbox(label="YouTube URL ์ž…๋ ฅ")
135
  analyze_button = gr.Button("๋ถ„์„ํ•˜๊ธฐ")
136
 
137
- title_output = gr.Textbox(label="์˜์ƒ ์ œ๋ชฉ")
138
-
139
  with gr.Tabs():
140
  with gr.TabItem("์›๋ฌธ ์Šคํฌ๋ฆฝํŠธ"):
141
  script_output = gr.Markdown()
@@ -145,7 +127,7 @@ with gr.Blocks() as demo:
145
  analyze_button.click(
146
  analyze,
147
  inputs=[youtube_url_input],
148
- outputs=[title_output, script_output, summary_output]
149
  )
150
 
151
  if __name__ == "__main__":
 
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
 
100
  progress(33, desc="์›๋ฌธ ์Šคํฌ๋ฆฝํŠธ ์ฒ˜๋ฆฌ ์ค‘...")
101
  script_sentences = split_sentences(script)
102
+ script_content = f"# {title}\n\n" + "\n".join(script_sentences)
103
 
104
  progress(66, desc="์š”์•ฝ ์ƒ์„ฑ ์ค‘...")
105
  summary = summarize_text(title, description, script)
106
+ summary_content = f"# {title}\n\n{summary}"
107
 
108
  progress(100, desc="์™„๋ฃŒ")
109
+ return script_content, summary_content
110
  except Exception as e:
111
  error_msg = f"์ฒ˜๋ฆฌ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ: {str(e)}"
112
  logging.exception(error_msg)
113
+ return error_msg, error_msg
114
 
115
  # Gradio ์ธํ„ฐํŽ˜์ด์Šค
116
  with gr.Blocks() as demo:
 
118
  youtube_url_input = gr.Textbox(label="YouTube URL ์ž…๋ ฅ")
119
  analyze_button = gr.Button("๋ถ„์„ํ•˜๊ธฐ")
120
 
 
 
121
  with gr.Tabs():
122
  with gr.TabItem("์›๋ฌธ ์Šคํฌ๋ฆฝํŠธ"):
123
  script_output = gr.Markdown()
 
127
  analyze_button.click(
128
  analyze,
129
  inputs=[youtube_url_input],
130
+ outputs=[script_output, summary_output]
131
  )
132
 
133
  if __name__ == "__main__":