import gradio as gr
import os
from threading import Thread
from llamafactory.chat import ChatModel
from llamafactory.extras.misc import torch_gc
# Set an environment variable
HF_TOKEN = os.environ.get("HF_TOKEN", None)
DESCRIPTION = '''
'
else:
avatar = '
'
return f'{avatar}
{content}
'
# Gradio block
chatbot = gr.Chatbot(height=450, placeholder=PLACEHOLDER, label='Gradio ChatInterface')
with gr.Blocks(css=css) as demo:
gr.Markdown(DESCRIPTION)
gr.DuplicateButton(value="Duplicate Space for private use", elem_id="duplicate-button")
def respond(message, history):
formatted_user_message = format_message('user', message)
history.append((message, formatted_user_message))
response = query_model(message, history)
formatted_ai_response = format_message('ai', next(response))
history.append((message, formatted_ai_response))
return history, history
chatbot = gr.Chatbot(label='Gradio ChatInterface')
input_text = gr.Textbox(label="Input", placeholder="Type your question here...")
send_button = gr.Button("Send")
send_button.click(respond, [input_text, chatbot], [chatbot, chatbot])
gr.Markdown(LICENSE)
if __name__ == "__main__":
demo.launch(share=True)