File size: 558 Bytes
40a6fd6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import gradio as gr
from transformers import pipeline, Conversation

chatbot = pipeline("conversational", model="facebook/blenderbot-400M-distill")

converse = None

def model_generate(text, state = None):
    if state == None:
        converse = Conversation(text)
    else:
        converse.add_user_input(text)

    converse = chatbot(converse)
    return converse.generated_responses[-1]

def get_response(text, history) -> str:
    output = model_generate(text, converse)
    return output

interface = gr.ChatInterface(get_response)
interface.launch()