seawolf2357 commited on
Commit
7e85524
โ€ข
1 Parent(s): 83ef4e2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -6
app.py CHANGED
@@ -11,9 +11,6 @@ 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)
@@ -25,7 +22,9 @@ def extract_keywords(text):
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']
@@ -35,10 +34,13 @@ def translate_and_extract_keywords(text):
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
  # ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์‹คํ–‰
 
11
  download('averaged_perceptron_tagger')
12
  download('stopwords')
13
 
 
 
 
14
  def extract_keywords(text):
15
  # ์˜์–ด ํ…์ŠคํŠธ๋ฅผ ํ† ํฐํ™”
16
  tokens = word_tokenize(text)
 
22
  keywords = [word for word, tag in tagged if tag in ['NN', 'NNP', 'NNS', 'VB', 'VBD', 'VBG', 'VBN', 'VBP', 'VBZ']]
23
  return ' '.join(keywords)
24
 
25
+ def translate_and_extract_keywords(text, api_key):
26
+ # ํด๋ผ์ด์–ธํŠธ ์„ค์ •
27
+ translate_client = translate.Client(credentials=translate.Credentials(api_key))
28
  # ์ž…๋ ฅ๋ฐ›์€ ํ•œ๊ธ€ ๋ฌธ์žฅ์„ ์˜์–ด๋กœ ๋ฒˆ์—ญ
29
  result = translate_client.translate(text, target_language='en')
30
  translated_text = result['translatedText']
 
34
  # Gradio ์ธํ„ฐํŽ˜์ด์Šค ์ •์˜
35
  interface = gr.Interface(
36
  fn=translate_and_extract_keywords,
37
+ inputs=[
38
+ gr.Textbox(lines=2, placeholder="ํ•œ๊ธ€ ๋ฌธ์žฅ์„ ์ž…๋ ฅํ•˜์„ธ์š”..."),
39
+ gr.Textbox(label="Google Cloud API ํ‚ค")
40
+ ],
41
  outputs="text",
42
  title="ํ•œ๊ธ€ ๋ฌธ์žฅ์„ ์˜์–ด ํ‚ค์›Œ๋“œ๋กœ ๋ฒˆ์—ญ ๋ฐ ์ถ”์ถœ",
43
+ description="ํ•œ๊ธ€ ๋ฌธ์žฅ๊ณผ Google Cloud API ํ‚ค๋ฅผ ์ž…๋ ฅํ•˜๋ฉด, ๊ทธ ์˜๋ฏธ๊ฐ€ ํฌํ•จ๋œ ์˜์–ด ํ‚ค์›Œ๋“œ๋ฅผ ์ถ”์ถœํ•˜์—ฌ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค."
44
  )
45
 
46
  # ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์‹คํ–‰