Spaces:
Sleeping
Sleeping
File size: 2,230 Bytes
fdbec52 90263a4 fdbec52 90263a4 fdbec52 90263a4 fdbec52 90263a4 fdbec52 |
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 |
from functions import *
# set the title
st.sidebar.title(DASHBOARD_TITLE)
info_section = st.empty()
# add an explanation of what is NER and why it is important for medical tasks
st.sidebar.markdown(
f"""
Meta Llama 3 8B Instruct is part of a family of large language models (LLMs) optimized for dialogue tasks.
This project uses Streamlit to create a simple chatbot interface that allows you to chat with the model using the Hugging Face Inference API.
Ask the model marketing-related questions and see how it responds. Have fun!
Model used: [{MODEL_PATH}]({MODEL_LINK})
"""
)
first_assistant_message = "Hello! I am Marketing expert. What can I help you with today?"
# clear conversation
if st.sidebar.button("Clear conversation"):
chat_history = [{'role':'assistant', 'content':first_assistant_message}]
st.session_state['chat_history'] = chat_history
st.rerun()
# Get the chat history
if "chat_history" not in st.session_state:
chat_history = [{'role':'assistant', 'content':first_assistant_message}]
st.session_state['chat_history'] = chat_history
else:
chat_history = st.session_state['chat_history']
# print the conversation
for message in chat_history:
with st.chat_message(message['role']):
st.write(message['content'])
# keep only last 50 messages
short_history = [message for message in chat_history[-50:] if 'content' in message]
# include a system prompt to explain the bot what to do
short_history = [{'role': 'system', 'content': SYSTEM_PROMPT}] + short_history
# get the input from user
user_input = st.chat_input("Write something...")
if user_input:
with st.chat_message("user"):
st.write(user_input)
# make the request
with st.spinner("Generating the response..."):
# create a shorter_history to avoid to keep a fair usage of the API
short_history = short_history + [{'role': 'user', 'content': user_input}]
# get the fill history for the next iteration
chat_history = make_request(user_input,
short_history,
chat_history)
st.session_state['chat_history'] = chat_history
st.rerun()
|