|
import streamlit as st |
|
from gradio_client import Client |
|
|
|
|
|
TITLE = "Llama2 70B Chatbot" |
|
DESCRIPTION = """ |
|
This Space demonstrates model [Llama-2-70b-chat-hf](https://huggingface.co/meta-llama/Llama-2-70b-chat-hf) by Meta, a Llama 2 model with 70B parameters fine-tuned for chat instructions. |
|
| Model | Llama2 | Llama2-hf | Llama2-chat | Llama2-chat-hf | |
|
|---|---|---|---|---| |
|
| 70B | [Link](https://huggingface.co/meta-llama/Llama-2-70b) | [Link](https://huggingface.co/meta-llama/Llama-2-70b-hf) | [Link](https://huggingface.co/meta-llama/Llama-2-70b-chat) | [Link](https://huggingface.co/meta-llama/Llama-2-70b-chat-hf) | |
|
""" |
|
|
|
|
|
|
|
|
|
with st.sidebar: |
|
|
|
temperatureSide = st.slider("Temperature", min_value=0.0, max_value=1.0, value=0.9, step=0.05) |
|
max_new_tokensSide = st.slider("Max new tokens", min_value=0.0, max_value=4096.0, value=4096.0, step=64.0) |
|
|
|
|
|
|
|
|
|
|
|
|
|
def predict(message, system_prompt='', temperature=0.7, max_new_tokens=4096,Topp=0.5,Repetitionpenalty=1.2): |
|
with st.status("Starting client"): |
|
client = Client("https://ysharma-explore-llamav2-with-tgi.hf.space/") |
|
st.write("Requesting client") |
|
with st.status("Requesting LLama-2"): |
|
st.write("Requesting API") |
|
response = client.predict( |
|
message, |
|
system_prompt, |
|
temperature, |
|
max_new_tokens, |
|
Topp, |
|
Repetitionpenalty, |
|
api_name="/chat" |
|
) |
|
st.write("Done") |
|
return response |
|
|
|
|
|
st.title(TITLE) |
|
st.write(DESCRIPTION) |
|
|
|
|
|
if "messages" not in st.session_state: |
|
st.session_state.messages = [] |
|
|
|
|
|
for message in st.session_state.messages: |
|
with st.chat_message(message["role"], avatar=("π§βπ»" if message["role"] == 'human' else 'π¦')): |
|
st.markdown(message["content"]) |
|
|
|
|
|
if prompt := st.chat_input("Ask LLama-2-70b anything..."): |
|
|
|
st.chat_message("human",avatar = "π§βπ»").markdown(prompt) |
|
|
|
st.session_state.messages.append({"role": "human", "content": prompt}) |
|
|
|
response = predict(message=prompt) |
|
|
|
with st.chat_message("assistant", avatar='π¦'): |
|
st.markdown(response) |
|
|
|
st.session_state.messages.append({"role": "assistant", "content": response}) |
|
|