Spaces:
Sleeping
Sleeping
Download app.py from Lurluberlu/chat: direct link, hf CLI and curl.
- Browser
- Download file 1.05 kB
-
https://huggingface.co/spaces/Lurluberlu/chat/resolve/main/app.py
- Command line
-
hf download hf://spaces/Lurluberlu/chat/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Lurluberlu/chat/resolve/main/app.py
1.05 kB
| 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}) | |