Update app.py
Browse files
app.py
CHANGED
@@ -2,12 +2,12 @@ import gradio as gr
|
|
2 |
import subprocess
|
3 |
import openai
|
4 |
import time
|
5 |
-
import
|
6 |
|
7 |
def translate(text_input, openapi_key):
|
8 |
openai.api_key = openapi_key
|
9 |
|
10 |
-
text_list = text_input.split('\n')[
|
11 |
|
12 |
reply = []
|
13 |
|
@@ -44,15 +44,15 @@ def translate_with_upload(text, file):
|
|
44 |
openapi_key = text
|
45 |
|
46 |
if file is not None:
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
else:
|
57 |
# νμΌμ΄ μ
λ‘λλμ§ μμ κ²½μ°, λΉ λ¬Έμμ΄λ‘ μ΄κΈ°νν©λλ€.
|
58 |
text_input = ""
|
|
|
2 |
import subprocess
|
3 |
import openai
|
4 |
import time
|
5 |
+
import re
|
6 |
|
7 |
def translate(text_input, openapi_key):
|
8 |
openai.api_key = openapi_key
|
9 |
|
10 |
+
text_list = text_input.split('\n')[8:]
|
11 |
|
12 |
reply = []
|
13 |
|
|
|
44 |
openapi_key = text
|
45 |
|
46 |
if file is not None:
|
47 |
+
text_input = file.read().decode('utf-8')
|
48 |
+
# ν
μ€νΈμμ μ½λ λΈλ‘μ μ κ±°ν©λλ€.
|
49 |
+
text_input = re.sub(r'```.*?```', '', text_input, flags=re.DOTALL)
|
50 |
+
|
51 |
+
text_input = re.sub(r'^\|.*\|$\n?', '', text_input, flags=re.MULTILINE)
|
52 |
+
|
53 |
+
# ν
μ€νΈμμ λΉ μ€μ μ κ±°ν©λλ€.
|
54 |
+
text_input = re.sub(r'^\n', '', text_input, flags=re.MULTILINE)
|
55 |
+
text_input = re.sub(r'\n\n+', '\n\n', text_input)
|
56 |
else:
|
57 |
# νμΌμ΄ μ
λ‘λλμ§ μμ κ²½μ°, λΉ λ¬Έμμ΄λ‘ μ΄κΈ°νν©λλ€.
|
58 |
text_input = ""
|