wseo-test Hyeonseo commited on
Commit
60a2f06
โ€ข
0 Parent(s):

Duplicate from Hyeonseo/ChatGPT-ko-translation-prompt

Browse files

Co-authored-by: Hyeonseo Yun <Hyeonseo@users.noreply.huggingface.co>

Files changed (4) hide show
  1. .gitattributes +34 -0
  2. README.md +14 -0
  3. app.py +76 -0
  4. requirements.txt +2 -0
.gitattributes ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tflite filter=lfs diff=lfs merge=lfs -text
29
+ *.tgz filter=lfs diff=lfs merge=lfs -text
30
+ *.wasm filter=lfs diff=lfs merge=lfs -text
31
+ *.xz filter=lfs diff=lfs merge=lfs -text
32
+ *.zip filter=lfs diff=lfs merge=lfs -text
33
+ *.zst filter=lfs diff=lfs merge=lfs -text
34
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: ChatGPT Ko Translation Prompt
3
+ emoji: ๐Ÿ“Š
4
+ colorFrom: blue
5
+ colorTo: purple
6
+ sdk: gradio
7
+ sdk_version: 3.28.0
8
+ app_file: app.py
9
+ pinned: false
10
+ license: apache-2.0
11
+ duplicated_from: Hyeonseo/ChatGPT-ko-translation-prompt
12
+ ---
13
+
14
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
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
+ # ๋ผ์ด์„ ์Šค ๋ฌธ์žฅ ์ œ๊ฑฐ
11
+ rm_line = text_input.find('-->')
12
+ text_list = text_input[rm_line+4:].split('\n')
13
+ print(text_list)
14
+
15
+ reply = []
16
+
17
+ for i in range(0,len(text_list),10):
18
+ content = """What do these sentences about Hugging Face Transformers (a machine learning library) mean in Korean? Please do not translate the word after a ๐Ÿค— emoji as it is a product name. Please ignore the video and image and translate only the sentences I provided. Ignore the contents of the iframe tag.
19
+ ```md
20
+ %s"""%'\n'.join(text_list[i:i+10])
21
+
22
+ chat = openai.ChatCompletion.create(
23
+ model = "gpt-3.5-turbo-0301", messages=[
24
+ {"role": "system",
25
+ "content": content},])
26
+
27
+ print("์งˆ๋ฌธ")
28
+ print(content)
29
+ print("์‘๋‹ต")
30
+ print(chat.choices[0].message.content)
31
+
32
+ reply.append(chat.choices[0].message.content)
33
+
34
+ time.sleep(30)
35
+
36
+ return ''.join(reply)
37
+
38
+ inputs = [
39
+ gr.inputs.Textbox(lines=2, label="Input Open API Key"),
40
+ gr.inputs.File(label="Upload MDX File")
41
+ ]
42
+
43
+ outputs = gr.outputs.Textbox(label="Translation")
44
+
45
+ def translate_with_upload(text, file):
46
+
47
+ openapi_key = text
48
+
49
+ if file is not None:
50
+ text_input = ""
51
+ with open(file.name, 'r') as f:
52
+ text_input += f.read()
53
+ text_input += '\n'
54
+ print(text_input)
55
+ # ํ…์ŠคํŠธ์—์„œ ์ฝ”๋“œ ๋ธ”๋ก์„ ์ œ๊ฑฐํ•ฉ๋‹ˆ๋‹ค.
56
+ text_input = re.sub(r'```.*?```', '', text_input, flags=re.DOTALL)
57
+
58
+ text_input = re.sub(r'^\|.*\|$\n?', '', text_input, flags=re.MULTILINE)
59
+
60
+ # ํ…์ŠคํŠธ์—์„œ ๋นˆ ์ค„์„ ์ œ๊ฑฐํ•ฉ๋‹ˆ๋‹ค.
61
+ text_input = re.sub(r'^\n', '', text_input, flags=re.MULTILINE)
62
+ text_input = re.sub(r'\n\n+', '\n\n', text_input)
63
+ else:
64
+ text_input = ""
65
+
66
+ return translate(text_input, openapi_key)
67
+
68
+ prompt_translate = gr.Interface(
69
+ fn=translate_with_upload,
70
+ inputs=inputs,
71
+ outputs=outputs,
72
+ title="ChatGPT Korean Prompt Translation",
73
+ description="Translate your text into Korean using the GPT-3 model.", verbose=True
74
+ )
75
+
76
+ prompt_translate.launch()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ openai
2
+ gradio