magictreee commited on
Commit
c31209b
ยท
verified ยท
1 Parent(s): 482667c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -9
app.py CHANGED
@@ -28,6 +28,32 @@ def get_youtube_script(url):
28
  api_name="/predict"
29
  )
30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  if not isinstance(result, str):
32
  result = str(result)
33
 
@@ -35,10 +61,10 @@ def get_youtube_script(url):
35
  raise ValueError("์ถ”์ถœ๋œ ์Šคํฌ๋ฆฝํŠธ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค.")
36
 
37
  title = "์ œ๋ชฉ ์—†์Œ"
38
- description = "์„ค๋ช… ์—†์Œ"
39
  transcription_text = result
40
 
41
- return title, description, transcription_text
 
42
  except Exception as e:
43
  raise ValueError(f"์Šคํฌ๋ฆฝํŠธ ์ถ”์ถœ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ: {str(e)}")
44
 
@@ -181,6 +207,7 @@ def get_blog_prompt():
181
  10. ์ฐธ๊ณ ๊ธ€์—์„œ '๋งํฌ๋ฅผ ํ™•์ธํ•ด์ฃผ์„ธ์š”'์™€ ๊ฐ™์€ ๋งํฌ ์ด๋™์˜ ๋ฌธ๊ตฌ๋Š” ์ œ์™ธ
182
  11. ์ฐธ๊ณ ๊ธ€์— ์žˆ๋Š” ์ž‘์„ฑ์ž, ํ™”์ž, ์œ ํŠœ๋ฒ„, ๊ธฐ์ž(Writer, speaker, YouTuber, reporter)์˜ ์ด๋ฆ„, ์• ์นญ, ๋‹‰๋„ค์ž„(Name, Nkickname)์€ ๋ฐ˜๋“œ์‹œ ์ œ์™ธ
183
  12. '์—…์ฒด๋กœ ๋ถ€ํ„ฐ ์ œ๊ณต ๋ฐ›์•„์„œ ์ž‘์„ฑ', '์ฟ ํŒก ํŒŒํŠธ๋„ˆ์Šค'๋“ฑ์˜ ํ‘œํ˜„์„ ๋ฐ˜๋“œ์‹œ ์ œ์™ธํ•˜๋ผ.
 
184
  [์—ฌํ–‰ ๋ธ”๋กœ๊ทธ ๊ธ€ ์ž‘์„ฑ ํ•„์ˆ˜ ๊ทœ์น™]
185
  1. ๋ธ”๋กœ๊ทธ ์ž‘์„ฑ์ž๊ฐ€ ์ง์ ‘ ๊ฒฝํ—˜ํ•˜๊ณ  ๋А๋‚€ ๋‚ด์šฉ๋งŒ ์ž‘์„ฑํ•˜์„ธ์š”.
186
  2. ์˜ค๊ฐ์— ๊ธฐ๋ฐ˜ํ•œ ์ƒ์ƒํ•œ ๋ฌ˜์‚ฌ ๋ฐ ์‹ค์šฉ ์ •๋ณด ํฌํ•จ
@@ -410,15 +437,14 @@ def save_pdf(blog_post):
410
  filename = save_to_pdf(content, title)
411
  return filename
412
 
413
- # ๋ฉ”์ธ ํ•จ์ˆ˜
414
  def process_youtube_url(url, style):
415
  max_retries = 2
416
  retry_count = 0
417
 
418
  while retry_count <= max_retries:
419
  try:
420
- # YouTube ์Šคํฌ๋ฆฝํŠธ ์ถ”์ถœ
421
- title, description, script = get_youtube_script(url)
422
 
423
  # ์Šคํฌ๋ฆฝํŠธ ๊ฒ€์ฆ
424
  if not script or not script.strip():
@@ -429,8 +455,8 @@ def process_youtube_url(url, style):
429
  # ์Šคํฌ๋ฆฝํŠธ ๋‚ด์šฉ๋งŒ ๋จผ์ € ๋ฐ˜ํ™˜
430
  yield script_content, "๋ธ”๋กœ๊ทธ ๊ธ€์„ ์ƒ์„ฑํ•˜๋Š” ์ค‘์ž…๋‹ˆ๋‹ค..."
431
 
432
- # ๋ธ”๋กœ๊ทธ ๊ธ€ ์ƒ์„ฑ
433
- blog_post = generate_blog_post(script, title, description, style)
434
 
435
  # ์ƒ์„ฑ๋œ ๋ธ”๋กœ๊ทธ ๊ธ€ ๋ฐ˜ํ™˜
436
  yield script_content, blog_post
@@ -445,8 +471,6 @@ def process_youtube_url(url, style):
445
  yield f"์ž๋ง‰์„ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. ์˜์ƒ์— ์ž๋ง‰์ด ์—†๊ฑฐ๋‚˜ ์ž๋ง‰์„ ๊ฐ€์ ธ์˜ค๋Š” ๋ฐ ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค. ์˜ค๋ฅ˜: {str(e)}", ""
446
  return
447
 
448
- yield "์ตœ๋Œ€ ์žฌ์‹œ๋„ ํšŸ์ˆ˜๋ฅผ ์ดˆ๊ณผํ–ˆ์Šต๋‹ˆ๋‹ค. ์ž๋ง‰์„ ๊ฐ€์ ธ์˜ค์ง€ ๋ชปํ–ˆ์Šต๋‹ˆ๋‹ค.", ""
449
-
450
  # Gradio ์ธํ„ฐํŽ˜์ด์Šค
451
  with gr.Blocks() as demo:
452
  gr.Markdown("## ์œ ํŠœ๋ธŒ -> ๋ธ”๋กœ๊ทธ - ์—ฌํ–‰")
 
28
  api_name="/predict"
29
  )
30
 
31
+ # ๊ฒฐ๊ณผ๊ฐ€ JSON ํ˜•์‹์ด๋ผ๋ฉด ํŒŒ์‹ฑํ•˜์—ฌ title๊ณผ transcriptionAsText๋งŒ ์ถ”์ถœ
32
+ if isinstance(result, dict) or (isinstance(result, str) and result.strip().startswith('{')):
33
+ if isinstance(result, str):
34
+ import json
35
+ try:
36
+ result = json.loads(result)
37
+ except:
38
+ pass
39
+
40
+ # JSON ๊ตฌ์กฐ์—์„œ ๋ฐ์ดํ„ฐ ์ถ”์ถœ
41
+ if isinstance(result, dict):
42
+ if 'data' in result and isinstance(result['data'], list) and len(result['data']) > 0:
43
+ data = result['data'][0]
44
+ title = data.get('title', "์ œ๋ชฉ ์—†์Œ")
45
+ transcription_text = data.get('transcriptionAsText', "")
46
+
47
+ # description์€ ๋ฐ˜ํ™˜ํ•˜์ง€ ์•Š์Œ
48
+ return title, transcription_text
49
+ elif 'title' in result and 'transcriptionAsText' in result:
50
+ title = result.get('title', "์ œ๋ชฉ ์—†์Œ")
51
+ transcription_text = result.get('transcriptionAsText', "")
52
+
53
+ # description์€ ๋ฐ˜ํ™˜ํ•˜์ง€ ์•Š์Œ
54
+ return title, transcription_text
55
+
56
+ # JSON์ด ์•„๋‹Œ ๊ฒฝ์šฐ ๊ฐ„๋‹จํ•˜๊ฒŒ ์ฒ˜๋ฆฌ
57
  if not isinstance(result, str):
58
  result = str(result)
59
 
 
61
  raise ValueError("์ถ”์ถœ๋œ ์Šคํฌ๋ฆฝํŠธ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค.")
62
 
63
  title = "์ œ๋ชฉ ์—†์Œ"
 
64
  transcription_text = result
65
 
66
+ # description์€ ๋ฐ˜ํ™˜ํ•˜์ง€ ์•Š์Œ
67
+ return title, transcription_text
68
  except Exception as e:
69
  raise ValueError(f"์Šคํฌ๋ฆฝํŠธ ์ถ”์ถœ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ: {str(e)}")
70
 
 
207
  10. ์ฐธ๊ณ ๊ธ€์—์„œ '๋งํฌ๋ฅผ ํ™•์ธํ•ด์ฃผ์„ธ์š”'์™€ ๊ฐ™์€ ๋งํฌ ์ด๋™์˜ ๋ฌธ๊ตฌ๋Š” ์ œ์™ธ
208
  11. ์ฐธ๊ณ ๊ธ€์— ์žˆ๋Š” ์ž‘์„ฑ์ž, ํ™”์ž, ์œ ํŠœ๋ฒ„, ๊ธฐ์ž(Writer, speaker, YouTuber, reporter)์˜ ์ด๋ฆ„, ์• ์นญ, ๋‹‰๋„ค์ž„(Name, Nkickname)์€ ๋ฐ˜๋“œ์‹œ ์ œ์™ธ
209
  12. '์—…์ฒด๋กœ ๋ถ€ํ„ฐ ์ œ๊ณต ๋ฐ›์•„์„œ ์ž‘์„ฑ', '์ฟ ํŒก ํŒŒํŠธ๋„ˆ์Šค'๋“ฑ์˜ ํ‘œํ˜„์„ ๋ฐ˜๋“œ์‹œ ์ œ์™ธํ•˜๋ผ.
210
+
211
  [์—ฌํ–‰ ๋ธ”๋กœ๊ทธ ๊ธ€ ์ž‘์„ฑ ํ•„์ˆ˜ ๊ทœ์น™]
212
  1. ๋ธ”๋กœ๊ทธ ์ž‘์„ฑ์ž๊ฐ€ ์ง์ ‘ ๊ฒฝํ—˜ํ•˜๊ณ  ๋А๋‚€ ๋‚ด์šฉ๋งŒ ์ž‘์„ฑํ•˜์„ธ์š”.
213
  2. ์˜ค๊ฐ์— ๊ธฐ๋ฐ˜ํ•œ ์ƒ์ƒํ•œ ๋ฌ˜์‚ฌ ๋ฐ ์‹ค์šฉ ์ •๋ณด ํฌํ•จ
 
437
  filename = save_to_pdf(content, title)
438
  return filename
439
 
 
440
  def process_youtube_url(url, style):
441
  max_retries = 2
442
  retry_count = 0
443
 
444
  while retry_count <= max_retries:
445
  try:
446
+ # YouTube ์Šคํฌ๋ฆฝํŠธ ์ถ”์ถœ (์ด์ œ title๊ณผ script๋งŒ ๋ฐ˜ํ™˜)
447
+ title, script = get_youtube_script(url)
448
 
449
  # ์Šคํฌ๋ฆฝํŠธ ๊ฒ€์ฆ
450
  if not script or not script.strip():
 
455
  # ์Šคํฌ๋ฆฝํŠธ ๋‚ด์šฉ๋งŒ ๋จผ์ € ๋ฐ˜ํ™˜
456
  yield script_content, "๋ธ”๋กœ๊ทธ ๊ธ€์„ ์ƒ์„ฑํ•˜๋Š” ์ค‘์ž…๋‹ˆ๋‹ค..."
457
 
458
+ # ๋ธ”๋กœ๊ทธ ๊ธ€ ์ƒ์„ฑ (description์€ ๋นˆ ๋ฌธ์ž์—ด๋กœ ์„ค์ •)
459
+ blog_post = generate_blog_post(script, title, "", style)
460
 
461
  # ์ƒ์„ฑ๋œ ๋ธ”๋กœ๊ทธ ๊ธ€ ๋ฐ˜ํ™˜
462
  yield script_content, blog_post
 
471
  yield f"์ž๋ง‰์„ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. ์˜์ƒ์— ์ž๋ง‰์ด ์—†๊ฑฐ๋‚˜ ์ž๋ง‰์„ ๊ฐ€์ ธ์˜ค๋Š” ๋ฐ ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค. ์˜ค๋ฅ˜: {str(e)}", ""
472
  return
473
 
 
 
474
  # Gradio ์ธํ„ฐํŽ˜์ด์Šค
475
  with gr.Blocks() as demo:
476
  gr.Markdown("## ์œ ํŠœ๋ธŒ -> ๋ธ”๋กœ๊ทธ - ์—ฌํ–‰")