File size: 2,293 Bytes
812f70a
 
 
5835e21
c6bb1bc
764f34e
 
ba913e7
764f34e
 
 
 
 
 
 
 
 
ba913e7
5835e21
 
 
 
 
 
 
 
 
764f34e
 
5835e21
 
 
 
 
 
 
 
 
764f34e
 
 
 
 
 
 
 
 
 
 
 
 
5835e21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# https://www.gradio.app/guides/using-hugging-face-integrations

import gradio as gr
from transformers import pipeline, Conversation

model = "mistralai/Mistral-7B-Instruct-v0.1"
model = "TinyLlama/TinyLlama-1.1B-Chat-v0.3"

title = "Shisa 7B"
description = "Test out Shisa 7B in either English or Japanese."
placeholder = "Type Here / ここにε…₯εŠ›γ—γ¦γγ γ•γ„" 
examples = [
    "Hello, how are you?", 
    "γ“γ‚“γ«γ‘γ―γ€ε…ƒζ°—γ§γ™γ‹οΌŸ",
    "γŠγ£γ™γ€ε…ƒζ°—οΌŸ",
    "γ“γ‚“γ«γ‘γ―γ€γ„γ‹γŒγŠιŽγ”γ—γ§γ™γ‹οΌŸ",
]

# Docs: https://github.com/huggingface/transformers/blob/main/src/transformers/pipelines/conversational.py
conversation = Conversation()
chatbot = pipeline('conversational', model)
'''
conversation = Conversation("Going to the movies tonight - any suggestions?")
conversation.add_message({"role": "assistant", "content": "The Big lebowski."})
conversation.add_message({"role": "user", "content": "Is it good?"})
conversation.messages[:-1]
'''

def chat(input, history=[]):
    conversation.add_message({"role": "user", "content": input})
    # we do this shuffle so local shadow response doesn't get created
    response_conversation = chatbot(conversation)
    print(response_conversation)
    print(response_conversation.messages)
    print(response_conversation.messages[-1]["content"])

    conversation.add_message(response_conversation.messages[-1])
    response = conversation.messages[-1]["content"]
    return response, history

gr.ChatInterface(
    chat,
    chatbot=gr.Chatbot(height=400),
    textbox=gr.Textbox(placeholder=placeholder, container=False, scale=7),
    title=title,
    description=description,
    theme="soft",
    examples=examples,
    cache_examples=False,
    undo_btn="Delete Previous",
    clear_btn="Clear",
).launch()

'''
gr.Interface.load(
    "EleutherAI/gpt-j-6B",
    inputs=gr.Textbox(lines=5, label="Input Text"),
    title=title,
    description=description,
    article=article,
).launch()


# Doesn't support conversational pipelin
pipe = pipeline('conversational', model)
gr.Interface.from_pipeline(pipe).launch()


'''


# For async
# ).queue().launch()

'''
# Pipeline doesn't support conversational...
pipe = pipeline("conversational", model=model)
demo = gr.Interface.from_pipeline(pipe)
'''