|
from chatterbot import ChatBot |
|
from chatterbot.trainers import ListTrainer |
|
import gradio as gr |
|
|
|
|
|
chatbot = ChatBot('WikiBot') |
|
|
|
|
|
trainer = ListTrainer(chatbot) |
|
|
|
|
|
with open('dataset.txt', 'r', encoding='utf-8') as file: |
|
data = file.readlines() |
|
|
|
|
|
trainer.train(data) |
|
|
|
|
|
def get_response(query): |
|
response = chatbot.get_response(query) |
|
return str(response) |
|
|
|
|
|
def chat_with_bot(user_input): |
|
return get_response(user_input) |
|
|
|
|
|
interface = gr.Interface( |
|
fn=chat_with_bot, |
|
inputs="text", |
|
outputs="text", |
|
title="WikiBot", |
|
description="Введите ваш вопрос и получите ответ от бота, обученного на данных из Википедии." |
|
) |
|
|
|
|
|
interface.launch() |
|
|