not-lain's picture
Update app.py
7b6ce24
raw
history blame
804 Bytes
# Use a pipeline as a high-level helper
from transformers import pipeline, Conversation
import gradio as gr
chatbot = pipeline("conversational", model="ericzhou/DialoGPT-Medium-Rick_v2")
conversation = None # initialization
def predict(sentence,history) :
global conversation
if not conversation :
# initial generation
conversation = Conversation(sentence)
else :
# mid conversation
conversation.add_user_input(sentence)
conversation = chatbot(conversation)
return conversation.generated_responses[-1]
header = """
<center>
<h1> chat with rick and morty </h1>
<img src="https://huggingface.co/spaces/not-lain/DialoGPT-Medium-Rick_v2/resolve/main/rick.png">
</center>
"""
with gr.Blocks() as iface :
gr.Markdown(header)
gr.ChatInterface(predict)
iface.queue().launch()