File size: 1,101 Bytes
7998dab
 
72bd82a
7998dab
0d64bfc
 
981542e
7998dab
 
 
758d5d3
7998dab
72bd82a
758d5d3
7998dab
 
72bd82a
 
ea2535d
72bd82a
7998dab
a92a9eb
085a76d
 
 
 
ea2535d
085a76d
7998dab
a92a9eb
7998dab
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from transformers import pipeline, Conversation
import gradio as gr
import time

chatbot = pipeline("text-generation", model="epfl-llm/meditron-7b", use_auth_token=True)
# chatbot = pipeline("translation", model="facebook/mbart-large-50-many-to-many-mmt", use_auth_token=True)

message_list = []
response_list = []

print("START")
def vanilla_chatbot(message, history):
    start = time.perf_counter()
    print("start chat")
    conversation = Conversation(text=message, past_user_inputs=message_list, generated_responses=response_list)
    conversation = chatbot(conversation)
    to_return = conversation.generated_responses[-1]
    
    print ("Answer in %5.1f secs " % (time.perf_counter() - start))
    return to_return

def chat_bot(message, history):
    start = time.perf_counter()
    print("start chat")
    to_return = chatbot(message, max_length=500)[0]['generated_text']

    print ("Answer in %5.1f secs " % (time.perf_counter() - start))
    return to_return

demo_chatbot = gr.ChatInterface(chat_bot, title="Check medical chatbot", description="Enter question")

demo_chatbot.launch()