File size: 1,767 Bytes
86b946a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
019cdf0
 
 
 
 
 
 
 
 
 
 
 
 
86b946a
 
 
 
 
883b37e
 
 
 
 
6e9959e
883b37e
 
 
e0d541d
883b37e
 
e0d541d
883b37e
 
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
import streamlit as st
from gradio_client import Client

# Constants
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. 
"""

# Initialize client
client = Client("https://ysharma-explore-llamav2-with-tgi.hf.space/")

# Prediction function
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,	# str in 'Message' Textbox component
                system_prompt,	# str in 'Optional system prompt' Textbox component
    			temperature,	# int | float (numeric value between 0.0 and 1.0)
    			max_new_tokens,	# int | float (numeric value between 0 and 4096)
    			0.3,	# int | float (numeric value between 0.0 and 1)
    			1,	# int | float (numeric value between 1.0 and 2.0)
    			api_name="/chat"
        )
        st.write("Done")
        return response

# Streamlit UI
st.title(TITLE)
st.write(DESCRIPTION)



# React to user input
if prompt := st.chat_input("Ask LLama-2-70b anything..."):
    # Display user message in chat message container
    st.chat_message("human",avatar = "πŸ§‘β€πŸ’»").markdown(prompt)
    # Add user message to chat history
    st.session_state.messages.append({"role": "human", "content": prompt})

    response = predict(prompt)
    # Display assistant response in chat message container
    with st.chat_message("assistant", avatar='πŸ¦™'):
        st.markdown(response)
    # Add assistant response to chat history
    st.session_state.messages.append({"role": "assistant", "content": response})