Hyeonseo commited on
Commit
5fa1a6d
β€’
1 Parent(s): 782faae

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -11
app.py CHANGED
@@ -2,12 +2,12 @@ import gradio as gr
2
  import subprocess
3
  import openai
4
  import time
5
- import os
6
 
7
  def translate(text_input, openapi_key):
8
  openai.api_key = openapi_key
9
 
10
- text_list = text_input.split('\n')[12:]
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
- new_filename = f"text_{file.name}"
49
- # sed λͺ…λ Ήμ–΄λ₯Ό μ‚¬μš©ν•˜μ—¬ νŒŒμΌμ„ λ³€ν™˜ν•©λ‹ˆλ‹€.
50
- subprocess.run(f"sed '/```/,/```/d' {file.name} | sed '/^|.*|$/d' | sed '/^$/N;/^\n$/D' > {new_filename}", shell=True)
51
- # μƒˆλ‘œμš΄ νŒŒμΌμ„ μ—΄μ–΄μ„œ λ‚΄μš©μ„ μ½μ–΄μ˜΅λ‹ˆλ‹€.
52
- with open(new_filename, 'r') as f:
53
- text_input = f.read()
54
- # μƒμ„±λœ νŒŒμΌμ„ μ‚­μ œν•©λ‹ˆλ‹€.
55
- os.remove(new_filename)
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 = ""