|
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. |
|
""" |
|
|
|
|
|
client = Client("https://ysharma-explore-llamav2-with-tgi.hf.space/") |
|
|
|
|
|
def predict(message, system_prompt="", temperature=0.9, max_new_tokens=4096): |
|
with st.status("Requesting LLama-2"): |
|
st.write("Requesting API") |
|
response = client.predict( |
|
message, |
|
system_prompt, |
|
temperature, |
|
max_new_tokens, |
|
0.3, |
|
1, |
|
api_name="/chat" |
|
) |
|
st.write("Done") |
|
return response |
|
|
|
|
|
st.title(TITLE) |
|
st.write(DESCRIPTION) |
|
|
|
|
|
|
|
|
|
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(prompt) |
|
|
|
with st.chat_message("assistant", avatar='π¦'): |
|
st.markdown(response) |
|
|
|
st.session_state.messages.append({"role": "assistant", "content": response}) |