shisa / app.py
lhl
Update app.py
4a8282c
raw
history blame
1.6 kB
# 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)