Spaces:
Sleeping
Sleeping
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)
|