Spaces:
Sleeping
Sleeping
File size: 1,048 Bytes
8ba36a3 | 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 | import streamlit as st
from transformers import AutoTokenizer
from huggingface_hub import InferenceClient
tokenizer = AutoTokenizer.from_pretrained("codellama/CodeLlama-34b-Instruct-hf")
client = InferenceClient(model="codellama/CodeLlama-34b-Instruct-hf", token=st.secrets["token"])
messages = [
]
if "messages" not in st.session_state:
st.session_state.messages = messages
for message in st.session_state.messages:
with st.chat_message(message["role"]):
st.markdown(message["content"])
if prompt := st.chat_input("Ecrire ..."):
st.session_state.messages.append({"role": "user", "content": prompt})
with st.chat_message("user"):
st.markdown(prompt)
with st.chat_message("assistant"):
encodeds = tokenizer.apply_chat_template(st.session_state.messages, return_tensors="pt", tokenize=False)
stream = client.text_generation(encodeds, max_new_tokens=1000, stream=True)
response = st.write_stream(stream)
st.session_state.messages.append({"role": "assistant", "content": response})
|