Spaces:
Sleeping
Sleeping
seawolf2357
commited on
Commit
โข
89ea00c
1
Parent(s):
4f8337d
Update app.py
Browse files
app.py
CHANGED
@@ -1,25 +1,45 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
-
from
|
|
|
|
|
|
|
|
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
# ์
๋ ฅ๋ฐ์ ํ๊ธ ๋ฌธ์ฅ์ ์์ด๋ก ๋ฒ์ญ
|
9 |
-
|
10 |
-
|
11 |
-
#
|
12 |
-
|
13 |
-
return translated_text.text
|
14 |
|
15 |
# Gradio ์ธํฐํ์ด์ค ์ ์
|
16 |
interface = gr.Interface(
|
17 |
-
fn=
|
18 |
inputs=gr.Textbox(lines=2, placeholder="ํ๊ธ ๋ฌธ์ฅ์ ์
๋ ฅํ์ธ์..."),
|
19 |
outputs="text",
|
20 |
-
title="ํ๊ธ ๋ฌธ์ฅ์ ์์ด ํค์๋๋ก ๋ฒ์ญ",
|
21 |
-
description="ํ๊ธ ๋ฌธ์ฅ์ ์
๋ ฅํ๋ฉด, ๊ทธ ์๋ฏธ๊ฐ ํฌํจ๋
|
22 |
)
|
23 |
|
24 |
# ์ ํ๋ฆฌ์ผ์ด์
์คํ
|
25 |
-
interface.launch()
|
|
|
1 |
+
import os
|
2 |
import gradio as gr
|
3 |
+
from google.cloud import translate_v2 as translate
|
4 |
+
from nltk import download
|
5 |
+
from nltk.tokenize import word_tokenize
|
6 |
+
from nltk.corpus import stopwords
|
7 |
+
from nltk import pos_tag
|
8 |
|
9 |
+
# nltk ๋ฐ์ดํฐ ๋ค์ด๋ก๋
|
10 |
+
download('punkt')
|
11 |
+
download('averaged_perceptron_tagger')
|
12 |
+
download('stopwords')
|
13 |
+
|
14 |
+
# Google Cloud Translation ํด๋ผ์ด์ธํธ ์ค์
|
15 |
+
translate_client = translate.Client()
|
16 |
+
|
17 |
+
def extract_keywords(text):
|
18 |
+
# ์์ด ํ
์คํธ๋ฅผ ํ ํฐํ
|
19 |
+
tokens = word_tokenize(text)
|
20 |
+
# ๋ถ์ฉ์ด ์ ๊ฑฐ ๋ฐ ์ค์ ๋จ์ด ์ถ์ถ
|
21 |
+
tokens = [word for word in tokens if word.isalnum() and word.lower() not in stopwords.words('english')]
|
22 |
+
# ํ์ฌ ํ๊น
|
23 |
+
tagged = pos_tag(tokens)
|
24 |
+
# ๋ช
์ฌ, ๊ณ ์ ๋ช
์ฌ, ๋์ฌ ์ค์ ํค์๋ ์ถ์ถ
|
25 |
+
keywords = [word for word, tag in tagged if tag in ['NN', 'NNP', 'NNS', 'VB', 'VBD', 'VBG', 'VBN', 'VBP', 'VBZ']]
|
26 |
+
return ' '.join(keywords)
|
27 |
+
|
28 |
+
def translate_and_extract_keywords(text):
|
29 |
# ์
๋ ฅ๋ฐ์ ํ๊ธ ๋ฌธ์ฅ์ ์์ด๋ก ๋ฒ์ญ
|
30 |
+
result = translate_client.translate(text, target_language='en')
|
31 |
+
translated_text = result['translatedText']
|
32 |
+
# ํค์๋ ์ถ์ถ
|
33 |
+
return extract_keywords(translated_text)
|
|
|
34 |
|
35 |
# Gradio ์ธํฐํ์ด์ค ์ ์
|
36 |
interface = gr.Interface(
|
37 |
+
fn=translate_and_extract_keywords,
|
38 |
inputs=gr.Textbox(lines=2, placeholder="ํ๊ธ ๋ฌธ์ฅ์ ์
๋ ฅํ์ธ์..."),
|
39 |
outputs="text",
|
40 |
+
title="ํ๊ธ ๋ฌธ์ฅ์ ์์ด ํค์๋๋ก ๋ฒ์ญ ๋ฐ ์ถ์ถ",
|
41 |
+
description="ํ๊ธ ๋ฌธ์ฅ์ ์
๋ ฅํ๋ฉด, ๊ทธ ์๋ฏธ๊ฐ ํฌํจ๋ ์์ด ํค์๋๋ฅผ ์ถ์ถํ์ฌ ์ถ๋ ฅํฉ๋๋ค."
|
42 |
)
|
43 |
|
44 |
# ์ ํ๋ฆฌ์ผ์ด์
์คํ
|
45 |
+
interface.launch(share=True)
|