File size: 1,599 Bytes
812f70a
 
 
5835e21
c6bb1bc
764f34e
45c171e
 
764f34e
ba913e7
764f34e
 
 
 
 
 
 
 
 
ba913e7
5835e21
 
 
764f34e
 
5835e21
 
 
 
 
 
 
 
 
764f34e
 
 
 
 
 
 
 
 
 
 
 
 
5835e21
 
 
4a8282c
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
# 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"

# Test Model
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)

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()

# For async
# ).queue().launch(share=True)