File size: 438 Bytes
a98fecc
3ad1bbb
 
dae99b3
 
a98fecc
 
dae99b3
a98fecc
 
0d8fbad
a98fecc
 
 
 
 
dae99b3
a98fecc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
from transformers import pipeline
import textwrap
import time
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()