chatbot / app.py
vivaceailab's picture
Update app.py
a05f62d verified
raw
history blame contribute delete
776 Bytes
import gradio as gr
from transformers import pipeline
# Hugging Face의 Helsinki-NLP Ko->Ru λ²ˆμ—­κΈ° μ‚¬μš©
translator = pipeline("translation_ko_to_ru", model="Helsinki-NLP/opus-mt-ko-ru")
def chat_translate(user_input):
if not user_input.strip():
return "μž…λ ₯을 ν•΄μ£Όμ„Έμš”!"
# λ²ˆμ—­
result = translator(user_input)
translated_text = result[0]['translation_text']
return translated_text
# κ°„λ‹¨ν•œ Gradio μ±— μΈν„°νŽ˜μ΄μŠ€
iface = gr.ChatInterface(
fn=chat_translate,
chatbot_name="ν•œκ΅­μ–΄->λŸ¬μ‹œμ•„μ–΄ λ²ˆμ—­ 챗봇",
title="ν•œκ΅­μ–΄ μž…λ ₯μ‹œ λŸ¬μ‹œμ•„μ–΄ λ²ˆμ—­ 챗봇",
description="ν•œκ΅­μ–΄λ‘œ μ§ˆλ¬Έν•˜λ©΄ λŸ¬μ‹œμ•„μ–΄λ‘œ λ²ˆμ—­ν•΄λ“œλ¦½λ‹ˆλ‹€."
)
if __name__ == "__main__":
iface.launch()