vivaceailab commited on
Commit
7704506
ยท
verified ยท
1 Parent(s): e46aa20

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -19
app.py CHANGED
@@ -1,26 +1,28 @@
1
  import gradio as gr
2
- from transformers import pipeline
3
 
4
- # Hugging Face์˜ Helsinki-NLP Ko->Ru ๋ฒˆ์—ญ๊ธฐ ์‚ฌ์šฉ
5
- translator = pipeline("translation_ko_to_ru", model="Helsinki-NLP/opus-mt-ko-ru")
 
 
6
 
7
- def chat_translate(user_input):
8
- if not user_input.strip():
9
- return "์ž…๋ ฅ์„ ํ•ด์ฃผ์„ธ์š”!"
10
-
11
- # ๋ฒˆ์—ญ
12
- result = translator(user_input)
13
- translated_text = result[0]['translation_text']
14
-
15
- return translated_text
16
 
17
- # ๊ฐ„๋‹จํ•œ Gradio ์ฑ— ์ธํ„ฐํŽ˜์ด์Šค
18
- iface = gr.ChatInterface(
19
- fn=chat_translate,
20
- chatbot_name="ํ•œ๊ตญ์–ด->๋Ÿฌ์‹œ์•„์–ด ๋ฒˆ์—ญ ์ฑ—๋ด‡",
21
- title="ํ•œ๊ตญ์–ด ์ž…๋ ฅ์‹œ ๋Ÿฌ์‹œ์•„์–ด ๋ฒˆ์—ญ ์ฑ—๋ด‡",
22
- description="ํ•œ๊ตญ์–ด๋กœ ์งˆ๋ฌธํ•˜๋ฉด ๋Ÿฌ์‹œ์•„์–ด๋กœ ๋ฒˆ์—ญํ•ด๋“œ๋ฆฝ๋‹ˆ๋‹ค."
 
23
  )
24
 
25
  if __name__ == "__main__":
26
- iface.launch()
 
1
  import gradio as gr
2
+ from transformers import MarianMTModel, MarianTokenizer
3
 
4
+ # ๋ชจ๋ธ๊ณผ ํ† ํฌ๋‚˜์ด์ € ๋กœ๋“œ
5
+ model_name = "Helsinki-NLP/opus-mt-ko-it"
6
+ tokenizer = MarianTokenizer.from_pretrained(model_name)
7
+ model = MarianMTModel.from_pretrained(model_name)
8
 
9
+ # ๋ฒˆ์—ญ ํ•จ์ˆ˜
10
+ def translate_korean_to_italian(text):
11
+ if not text.strip():
12
+ return "โš ๏ธ ๋ฒˆ์—ญํ•  ๋ฌธ์žฅ์„ ์ž…๋ ฅํ•˜์„ธ์š”."
13
+ inputs = tokenizer(text, return_tensors="pt", padding=True)
14
+ translated = model.generate(**inputs)
15
+ result = tokenizer.decode(translated[0], skip_special_tokens=True)
16
+ return result
 
17
 
18
+ # Gradio ์ธํ„ฐํŽ˜์ด์Šค ๊ตฌ์„ฑ
19
+ interface = gr.Interface(
20
+ fn=translate_korean_to_italian,
21
+ inputs=gr.Textbox(lines=2, label="ํ•œ๊ตญ์–ด ์ž…๋ ฅ"),
22
+ outputs=gr.Textbox(label="์ดํƒˆ๋ฆฌ์•„์–ด ๋ฒˆ์—ญ"),
23
+ title="ํ•œ๊ตญ์–ด โ†’ ์ดํƒˆ๋ฆฌ์•„์–ด ๋ฒˆ์—ญ๊ธฐ",
24
+ description="ํ•œ๊ตญ์–ด ๋ฌธ์žฅ์„ ์ž…๋ ฅํ•˜๋ฉด ์ดํƒˆ๋ฆฌ์•„์–ด๋กœ ๋ฒˆ์—ญํ•ฉ๋‹ˆ๋‹ค. ๋ชจ๋ธ: Helsinki-NLP/opus-mt-ko-it"
25
  )
26
 
27
  if __name__ == "__main__":
28
+ interface.launch()