Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,73 +1,288 @@
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
-
import openai
|
| 3 |
|
| 4 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
"""
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
"""
|
| 16 |
openai.api_key = os.getenv("OPENAI_API_KEY")
|
| 17 |
if not openai.api_key:
|
| 18 |
-
return
|
| 19 |
-
"์ค๋ฅ: OPENAI_API_KEY๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค.",
|
| 20 |
-
"์์ ๋ด์ญ ์์"
|
| 21 |
-
)
|
| 22 |
|
| 23 |
system_prompt = (
|
| 24 |
"๋น์ ์ ํ๊ตญ์ด ๋ฌธ์ฅ ๊ต์ ์ ๋ฌธ๊ฐ์
๋๋ค.\n"
|
| 25 |
-
"์๋์ [๊ท์น]์ ์งํค๋ฉด์ ํ
์คํธ๋ฅผ ๊ต์ ํด ์ฃผ์ธ์.\n"
|
| 26 |
"[๊ท์น]\n"
|
| 27 |
-
"1) (๊ธฐ์กด) ์์ ์ฌํญ ํ
์คํธ๋ฅผ ์ฐ์ ๊ทธ๋๋ก
|
| 28 |
-
"2) ์ค๋ฐ๊ฟ
|
| 29 |
-
" -
|
| 30 |
-
" -
|
| 31 |
-
"
|
| 32 |
-
"
|
| 33 |
-
"
|
| 34 |
-
"4) ์ ๋ ์์๋ก ๋ด์ฉ์ ๋ฐ๊พธ์ง ์๋๋ค.\n"
|
| 35 |
-
)
|
| 36 |
-
|
| 37 |
-
user_prompt = (
|
| 38 |
-
f"์๋ ํ
์คํธ๋ฅผ [๊ท์น]์ ๋ฐ๋ผ ๊ต์ ํด ์ฃผ์ธ์.\n"
|
| 39 |
-
f"```\n{old_changes_summary_text}\n```"
|
| 40 |
-
"\n\n"
|
| 41 |
"์ถ๋ ฅ ํ์:\n"
|
| 42 |
-
"๊ต์ ๋ ๋ณธ๋ฌธ
|
|
|
|
| 43 |
"=== ์์ ๋ด์ญ ===\n"
|
| 44 |
-
"
|
| 45 |
)
|
| 46 |
|
|
|
|
|
|
|
| 47 |
try:
|
| 48 |
-
# (์: ์ต์ openai 1.0.0+ ์์๋ ChatCompletion ๋ฐฉ์์ ๊ณ์ ์ง์)
|
| 49 |
response = openai.ChatCompletion.create(
|
| 50 |
-
model="gpt-4o-mini", # ์ค์
|
| 51 |
messages=[
|
| 52 |
{"role": "system", "content": system_prompt},
|
| 53 |
-
{"role": "user", "content": user_prompt}
|
| 54 |
],
|
| 55 |
temperature=0.0
|
| 56 |
)
|
| 57 |
raw_output = response.choices[0].message["content"].strip()
|
| 58 |
except Exception as e:
|
| 59 |
-
return (
|
| 60 |
-
f"LLM ํธ์ถ ์ค๋ฅ: {str(e)}",
|
| 61 |
-
"์์ ๋ด์ญ ์ ๋ณด ์์ฑ ์คํจ"
|
| 62 |
-
)
|
| 63 |
|
| 64 |
-
#
|
| 65 |
-
# ๊ต์ ๋ ๋ณธ๋ฌธ
|
|
|
|
| 66 |
# === ์์ ๋ด์ญ ===
|
| 67 |
-
# (์์
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
else:
|
| 72 |
-
|
| 73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
import re
|
| 4 |
import os
|
| 5 |
+
import openai # openai ์ต์ ๋ฒ์ (>=1.0.0) ๊ฐ์
|
| 6 |
|
| 7 |
+
def debug_print(*args):
|
| 8 |
+
"""๋๋ฒ๊น
์ฉ ์ฝ์ ์ถ๋ ฅ"""
|
| 9 |
+
print("[DEBUG]", *args)
|
| 10 |
+
|
| 11 |
+
########################################################
|
| 12 |
+
# (1) ๊ธฐ์กด ํจ์๋ค: parse_track_number, fetch_script, show_next_field
|
| 13 |
+
########################################################
|
| 14 |
+
|
| 15 |
+
def parse_track_number(input_text):
|
| 16 |
+
debug_print("parse_track_number() called with:", input_text)
|
| 17 |
+
match = re.search(r'<track[^>]*\skind="captions"[^>]*\ssrc="([^"]+)"', input_text)
|
| 18 |
+
if not match:
|
| 19 |
+
debug_print("ํธ๋ ํ๊ทธ(kinds='captions')์์ src ์ถ์ถ ์คํจ")
|
| 20 |
+
return None
|
| 21 |
+
|
| 22 |
+
track_number = match.group(1).strip()
|
| 23 |
+
debug_print("์ด๊ธฐ ์ถ์ถ track_number:", track_number)
|
| 24 |
+
|
| 25 |
+
# blob: ์ ๊ฑฐ
|
| 26 |
+
if 'blob:' in track_number:
|
| 27 |
+
track_number = track_number.replace('blob:', '')
|
| 28 |
+
debug_print("blob: ์ ๊ฑฐ ํ:", track_number)
|
| 29 |
+
|
| 30 |
+
# https://player.vimeo.com ์ ๊ฑฐ
|
| 31 |
+
if 'https://player.vimeo.com' in track_number:
|
| 32 |
+
track_number = track_number.replace('https://player.vimeo.com', '')
|
| 33 |
+
debug_print("๋๋ฉ์ธ ์ ๊ฑฐ ํ:", track_number)
|
| 34 |
+
|
| 35 |
+
track_number = track_number.strip()
|
| 36 |
+
if not track_number.startswith('/'):
|
| 37 |
+
track_number = '/' + track_number
|
| 38 |
+
debug_print("์์ '/' ์ถ๊ฐ ํ:", track_number)
|
| 39 |
+
|
| 40 |
+
debug_print("์ต์ข
track_number:", track_number)
|
| 41 |
+
return track_number
|
| 42 |
+
|
| 43 |
+
def fetch_script(url):
|
| 44 |
+
"""URL(๋ฌธ์์ด)์์ ํธ๋๋ฒํธ ์ถ์ถ ํ, Vimeo ์๋ง URL๋ก GET ์์ฒญ."""
|
| 45 |
+
track_number = parse_track_number(url)
|
| 46 |
+
if not track_number:
|
| 47 |
+
return "ํธ๋๋ฒํธ๋ฅผ ์ฐพ์ง ๋ชปํ์ต๋๋ค. ์: <track kind='captions' src='/1234567.vtt' ...>"
|
| 48 |
+
|
| 49 |
+
target_url = f"https://player.vimeo.com{track_number}"
|
| 50 |
+
debug_print("์ ์ํ URL:", target_url)
|
| 51 |
+
try:
|
| 52 |
+
resp = requests.get(target_url)
|
| 53 |
+
if resp.status_code == 200:
|
| 54 |
+
debug_print("์๋ง ์คํฌ๋ฆฝํธ ๊ฐ์ ธ์ค๊ธฐ ์ฑ๊ณต")
|
| 55 |
+
return resp.text
|
| 56 |
+
else:
|
| 57 |
+
debug_print("HTTP ์๋ฌ:", resp.status_code)
|
| 58 |
+
return f"HTTP ์๋ฌ: {resp.status_code}"
|
| 59 |
+
except Exception as e:
|
| 60 |
+
debug_print("์์ธ ๋ฐ์:", str(e))
|
| 61 |
+
return f"์๋ฌ ๋ฐ์: {str(e)}"
|
| 62 |
+
|
| 63 |
+
def show_next_field(num_visible):
|
| 64 |
+
"""
|
| 65 |
+
+ ๋ฒํผ ํด๋ฆญ ์, URL ์
๋ ฅ์นธ ํ๋์ฉ ์ถ๊ฐํด์ ์ต๋ 5๊ฐ๊น์ง ํ์.
|
| 66 |
+
"""
|
| 67 |
+
debug_print("show_next_field() called. Current:", num_visible)
|
| 68 |
+
if num_visible < 5:
|
| 69 |
+
num_visible += 1
|
| 70 |
+
updates = []
|
| 71 |
+
for i in range(1, 6):
|
| 72 |
+
updates.append(gr.update(visible=(i <= num_visible)))
|
| 73 |
+
|
| 74 |
+
return [num_visible] + updates
|
| 75 |
+
|
| 76 |
+
########################################################
|
| 77 |
+
# (2) (๊ธฐ์กด) ์ ์ฒด ์คํฌ๋ฆฝํธ ๋ง๋ค๊ธฐ
|
| 78 |
+
########################################################
|
| 79 |
+
|
| 80 |
+
def is_vtt_timeline_line(line: str) -> bool:
|
| 81 |
+
# ์: 00:49:33.920 --> 00:49:38.700
|
| 82 |
+
pattern = r'^\d{2}:\d{2}:\d{2}(\.\d+)?\s*-->\s*\d{2}:\d{2}:\d{2}(\.\d+)?$'
|
| 83 |
+
return bool(re.match(pattern, line.strip()))
|
| 84 |
+
|
| 85 |
+
def is_number_line(line: str) -> bool:
|
| 86 |
+
# ์: 1, 2., 3)
|
| 87 |
+
pattern = r'^\d+[\.\)]?$'
|
| 88 |
+
return bool(re.match(pattern, line.strip()))
|
| 89 |
+
|
| 90 |
+
def is_webvtt_header(line: str) -> bool:
|
| 91 |
+
# ์: WEBVTT
|
| 92 |
+
return line.strip() == "WEBVTT"
|
| 93 |
+
|
| 94 |
+
def combine_scripts(script1, script2, script3, script4, script5):
|
| 95 |
+
"""
|
| 96 |
+
- (๊ธฐ์กด) ์ ์ฒด ์คํฌ๋ฆฝํธ: ์๋ณธ ๊ทธ๋๋ก ํฉ์นจ + [๊ฐ์N] ํค๋
|
| 97 |
+
- (๊ธฐ์กด) ์์ ์ฌํญ: ํ์๋ผ์ธ/์ซ์/WEBVTT ์ ๊ฑฐ + [๊ฐ์N] ํค๋
|
| 98 |
+
"""
|
| 99 |
+
scripts = [script1, script2, script3, script4, script5]
|
| 100 |
+
merged_full = []
|
| 101 |
+
merged_filtered = []
|
| 102 |
+
|
| 103 |
+
for idx, sc in enumerate(scripts, start=1):
|
| 104 |
+
if not sc or not sc.strip():
|
| 105 |
+
continue
|
| 106 |
+
|
| 107 |
+
lines = sc.splitlines()
|
| 108 |
+
|
| 109 |
+
# (A) ์ ์ฒด ์คํฌ๋ฆฝํธ
|
| 110 |
+
merged_full.append(f"[๊ฐ์{idx}]")
|
| 111 |
+
merged_full.extend(lines)
|
| 112 |
+
|
| 113 |
+
# (B) ์์ ์ฌํญ
|
| 114 |
+
merged_filtered.append(f"[๊ฐ์{idx}]")
|
| 115 |
+
for line in lines:
|
| 116 |
+
if is_vtt_timeline_line(line):
|
| 117 |
+
continue
|
| 118 |
+
if is_number_line(line):
|
| 119 |
+
continue
|
| 120 |
+
if is_webvtt_header(line):
|
| 121 |
+
continue
|
| 122 |
+
merged_filtered.append(line)
|
| 123 |
+
|
| 124 |
+
old_combined_script = "\n".join(merged_full)
|
| 125 |
+
old_changes_summary = "\n".join(merged_filtered)
|
| 126 |
+
return old_combined_script, old_changes_summary
|
| 127 |
+
|
| 128 |
+
########################################################
|
| 129 |
+
# (3) LLM ํธ์ถ ๋ก์ง - ์๋ก์ด ์ง์์ฌํญ
|
| 130 |
+
########################################################
|
| 131 |
+
|
| 132 |
+
def refine_with_llm(old_changes_summary_text):
|
| 133 |
"""
|
| 134 |
+
[์๋ก์ด ์๊ตฌ์ฌํญ]:
|
| 135 |
+
1. (๊ธฐ์กด) ์์ ์ฌํญ ๋ด์ฉ ์ฐ์ ๊ธฐ์ต
|
| 136 |
+
2. ์ค๋ฐ๊ฟ/๋์ด์ฐ๊ธฐ ๋ฌธ๋งฅ์ ๋ง๊ฒ ์ฌ๊ตฌ์ฑ (๋ถ์ด๊ณ /๋๋๊ณ )
|
| 137 |
+
3. ์ ๋ ๋ด์ฉ ์ค์ด๊ฑฐ๋ ์์ฝ/์ญ์ /์์๋ณ๊ฒฝํ์ง ๋ง๊ธฐ
|
| 138 |
+
4. ์คํ/๋ง์ถค๋ฒ๋ง ์์
|
| 139 |
+
5. ์์ ํ ๋ถ๋ถ ๋ชจ๋ ์ ๋ฆฌํ์ฌ ์๋ ค์ฃผ๊ธฐ
|
| 140 |
+
|
| 141 |
+
์ถ๋ ฅํ์:
|
| 142 |
+
(๊ต์ ๋ ๋ณธ๋ฌธ, ์์ ๋ด์ญ)
|
| 143 |
+
|
| 144 |
+
LLM ์๋ต ์์:
|
| 145 |
+
๊ต์ ๋ ๋ณธ๋ฌธ
|
| 146 |
+
=== ์์ ๋ด์ญ ===
|
| 147 |
+
(์ด์ -> ์ดํ ๋ชฉ๋ก)
|
| 148 |
"""
|
| 149 |
openai.api_key = os.getenv("OPENAI_API_KEY")
|
| 150 |
if not openai.api_key:
|
| 151 |
+
return "์ค๋ฅ: OPENAI_API_KEY๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค.", "์์ ๋ด์ญ ์์"
|
|
|
|
|
|
|
|
|
|
| 152 |
|
| 153 |
system_prompt = (
|
| 154 |
"๋น์ ์ ํ๊ตญ์ด ๋ฌธ์ฅ ๊ต์ ์ ๋ฌธ๊ฐ์
๋๋ค.\n"
|
|
|
|
| 155 |
"[๊ท์น]\n"
|
| 156 |
+
"1) (๊ธฐ์กด) ์์ ์ฌํญ ํ
์คํธ๋ฅผ ์ฐ์ ๊ทธ๋๋ก.\n"
|
| 157 |
+
"2) ์ค๋ฐ๊ฟ/๋์ด์ฐ๊ธฐ๋ฅผ ๋ฌธ๋งฅ์ ๋ง๊ฒ ์ฌ๊ตฌ์ฑ.\n"
|
| 158 |
+
" - ๋ถ์ฌ์ผ ํ ๋ฌธ๋จ์ ๋ถ์ด๊ณ \n"
|
| 159 |
+
" - ๋ถ๋ฆฌํด์ผ ํ ๋ฌธ๋จ์ ๋ถ๋ฆฌ.\n"
|
| 160 |
+
"3) ์ ๋ ๋ด์ฉ์ ์์ฝ/์ญ์ /์์ ๋ณ๊ฒฝํ์ง ๋ง ๊ฒ.\n"
|
| 161 |
+
"4) ์คํ๋ ๋ง์ถค๋ฒ๋ง ์์ .\n"
|
| 162 |
+
"5) ์์ ํ ๋ถ๋ถ์ ๋ชจ๋ ์ ๋ฆฌํด ์๋ ค์ค ๊ฒ.\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
"์ถ๋ ฅ ํ์:\n"
|
| 164 |
+
"=== ๊ต์ ๋ ๋ณธ๋ฌธ ===\n"
|
| 165 |
+
"(์ฌ๊ตฌ์ฑ+๋ง์ถค๋ฒ ์์ ๋ ๋ณธ๋ฌธ)\n"
|
| 166 |
"=== ์์ ๋ด์ญ ===\n"
|
| 167 |
+
"(์ด์ -> ์ดํ) ๋ฑ ๋ชจ๋ ๋ณ๊ฒฝ์ฌํญ ๋ฆฌ์คํธ.\n"
|
| 168 |
)
|
| 169 |
|
| 170 |
+
user_prompt = f"์๋ ํ
์คํธ๋ฅผ ๊ต์ ํด ์ฃผ์ธ์:\n```\n{old_changes_summary_text}\n```"
|
| 171 |
+
|
| 172 |
try:
|
|
|
|
| 173 |
response = openai.ChatCompletion.create(
|
| 174 |
+
model="gpt-4o-mini", # ์ค์ ์กด์ฌX ๊ฐ๋ฅ์ฑ. ํ์์ gpt-3.5-turbo ๋ฑ ์ฌ์ฉ
|
| 175 |
messages=[
|
| 176 |
{"role": "system", "content": system_prompt},
|
| 177 |
+
{"role": "user", "content": user_prompt},
|
| 178 |
],
|
| 179 |
temperature=0.0
|
| 180 |
)
|
| 181 |
raw_output = response.choices[0].message["content"].strip()
|
| 182 |
except Exception as e:
|
| 183 |
+
return f"LLM ํธ์ถ ์ค๋ฅ: {str(e)}", "์์ ๋ด์ญ ์์ฑ ์คํจ"
|
|
|
|
|
|
|
|
|
|
| 184 |
|
| 185 |
+
# ์ถ๋ ฅ ์์:
|
| 186 |
+
# === ๊ต์ ๋ ๋ณธ๋ฌธ ===
|
| 187 |
+
# (๋ณธ๋ฌธ)
|
| 188 |
# === ์์ ๋ด์ญ ===
|
| 189 |
+
# (์์ ๋ฆฌ์คํธ)
|
| 190 |
+
corrected_sep = "=== ๊ต์ ๋ ๋ณธ๋ฌธ ==="
|
| 191 |
+
changes_sep = "=== ์์ ๋ด์ญ ==="
|
| 192 |
+
|
| 193 |
+
corrected_text = ""
|
| 194 |
+
changes_text = ""
|
| 195 |
+
|
| 196 |
+
if corrected_sep in raw_output and changes_sep in raw_output:
|
| 197 |
+
# ๊ต์ ๋ ๋ณธ๋ฌธ
|
| 198 |
+
part1 = raw_output.split(corrected_sep, 1)[1]
|
| 199 |
+
if changes_sep in part1:
|
| 200 |
+
corrected_text, changes_text = part1.split(changes_sep, 1)
|
| 201 |
+
corrected_text = corrected_text.strip()
|
| 202 |
+
changes_text = changes_text.strip()
|
| 203 |
+
else:
|
| 204 |
+
corrected_text = part1.strip()
|
| 205 |
+
changes_text = "์์ ๋ด์ญ ๊ตฌ๋ถ ์์"
|
| 206 |
else:
|
| 207 |
+
corrected_text = raw_output
|
| 208 |
+
changes_text = "LLM ์๋ต์ ์์ ๋ด์ญ ๊ตฌ๋ถ ์์"
|
| 209 |
+
|
| 210 |
+
return corrected_text, changes_text
|
| 211 |
+
|
| 212 |
+
########################################################
|
| 213 |
+
# (4) build_app: Gradio UI
|
| 214 |
+
########################################################
|
| 215 |
+
|
| 216 |
+
def build_app():
|
| 217 |
+
with gr.Blocks() as demo:
|
| 218 |
+
gr.Markdown("## ๊ฐ์ URL ์
๋ ฅ ๋ฐ ์คํฌ๋ฆฝํธ ์ฒ๋ฆฌ")
|
| 219 |
+
|
| 220 |
+
num_visible = gr.State(value=2)
|
| 221 |
+
script_outputs = []
|
| 222 |
+
row_list = []
|
| 223 |
+
|
| 224 |
+
# ์ต๋ 5๊ฐ URL ์
๋ ฅ
|
| 225 |
+
for i in range(1, 6):
|
| 226 |
+
with gr.Row(visible=(i <= 2)) as row:
|
| 227 |
+
with gr.Column():
|
| 228 |
+
url_inp = gr.Textbox(
|
| 229 |
+
label=f"๊ฐ์{i} URL ์
๋ ฅ",
|
| 230 |
+
placeholder="์: <track kind='captions' src='/1234567.vtt' ...>"
|
| 231 |
+
)
|
| 232 |
+
fetch_btn = gr.Button("์คํฌ๋ฆฝํธ ๊ฐ์ ธ์ค๊ธฐ")
|
| 233 |
+
script_box = gr.Textbox(label=f"๊ฐ์{i} ์คํฌ๋ฆฝํธ", lines=8)
|
| 234 |
+
|
| 235 |
+
fetch_btn.click(fetch_script, inputs=url_inp, outputs=script_box)
|
| 236 |
+
row_list.append(row)
|
| 237 |
+
script_outputs.append(script_box)
|
| 238 |
+
|
| 239 |
+
plus_button = gr.Button("+")
|
| 240 |
+
plus_button.click(show_next_field, inputs=num_visible, outputs=[num_visible]+row_list)
|
| 241 |
+
|
| 242 |
+
# (๊ธฐ์กด) ์ ์ฒด ์คํฌ๋ฆฝํธ ๋ง๋ค๊ธฐ
|
| 243 |
+
with gr.Row():
|
| 244 |
+
old_combine_btn = gr.Button("(๊ธฐ์กด) ์ ์ฒด ์คํฌ๋ฆฝํธ ๋ง๋ค๊ธฐ")
|
| 245 |
+
with gr.Row():
|
| 246 |
+
old_combined_box = gr.Textbox(
|
| 247 |
+
label="(๊ธฐ์กด) ์ ์ฒด ์คํฌ๋ฆฝํธ",
|
| 248 |
+
lines=8
|
| 249 |
+
)
|
| 250 |
+
old_changes_box = gr.Textbox(
|
| 251 |
+
label="(๊ธฐ์กด) ์์ ์ฌํญ",
|
| 252 |
+
lines=8
|
| 253 |
+
)
|
| 254 |
+
|
| 255 |
+
# combine_scripts -> (๊ธฐ์กด) ์ ์ฒด ์คํฌ๋ฆฝํธ, (๊ธฐ์กด) ์์ ์ฌํญ
|
| 256 |
+
old_combine_btn.click(
|
| 257 |
+
fn=combine_scripts,
|
| 258 |
+
inputs=script_outputs,
|
| 259 |
+
outputs=[old_combined_box, old_changes_box]
|
| 260 |
+
)
|
| 261 |
+
|
| 262 |
+
# LLM ๊ต์
|
| 263 |
+
with gr.Row():
|
| 264 |
+
llm_btn = gr.Button("LLM(์ ๊ต์ ) - ๊ฐ์๋ด์ฉ ์ ๋ฆฌ")
|
| 265 |
+
|
| 266 |
+
with gr.Row():
|
| 267 |
+
corrected_box = gr.Textbox(
|
| 268 |
+
label="๊ต์ ๋ ๋ณธ๋ฌธ",
|
| 269 |
+
lines=10,
|
| 270 |
+
placeholder="์ค๋ฐ๊ฟ/๋์ด์ฐ๊ธฐ ์ฌ๊ตฌ์ฑ + ๋ง์ถค๋ฒ ์์ ๊ฒฐ๊ณผ"
|
| 271 |
+
)
|
| 272 |
+
changes_box = gr.Textbox(
|
| 273 |
+
label="์์ ๋ด์ญ",
|
| 274 |
+
lines=8,
|
| 275 |
+
placeholder="์คํ/๋ง์ถค๋ฒ ์์ ๋ ๋ถ๋ถ ์์ฝ"
|
| 276 |
+
)
|
| 277 |
+
|
| 278 |
+
llm_btn.click(
|
| 279 |
+
fn=refine_with_llm,
|
| 280 |
+
inputs=old_changes_box, # (๊ธฐ์กด) ์์ ์ฌํญ
|
| 281 |
+
outputs=[corrected_box, changes_box]
|
| 282 |
+
)
|
| 283 |
+
|
| 284 |
+
return demo
|
| 285 |
+
|
| 286 |
+
if __name__ == "__main__":
|
| 287 |
+
demo = build_app()
|
| 288 |
+
demo.launch()
|