from transformers import pipeline | |
import gradio as gr | |
# Load a pre-trained chatbot model | |
chatbot = pipeline("conversational") | |
def wrap(x): | |
return textwrap.fill(x, replace_whitespace=False, fix_sentence_endings=True) | |
def chat(prompt): | |
out = chatbot(prompt) | |
for i in wrap(out[0]['generated_text']): | |
print(i, end='') | |
time.sleep(0.2) | |
gr.Interface(fn=chat, inputs="text", outputs="text").launch() | |