File size: 2,336 Bytes
362e436
 
 
 
89cf3f4
362e436
 
89cf3f4
 
362e436
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5c244e3
362e436
 
 
 
b219231
7df5b30
63dd0e9
 
e50bcc2
63dd0e9
b219231
362e436
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5ebc2df
eb144b2
362e436
 
eb144b2
 
c30b9da
362e436
c30b9da
362e436
 
 
 
 
 
b219231
 
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import streamlit as st
import os
from together import Together

from utils.helper import *


st.set_page_config(layout="wide")
st.title("Meta Llama3 πŸ¦™")


with st.sidebar:
    with st.expander("Instruction Manual"):
        st.markdown("""
            ## Meta Llama3 πŸ¦™ Chatbot

            This Streamlit app allows you to chat with Meta's Llama3 model.

            ### How to Use:
            1. **Input**: Type your prompt into the chat input box labeled "What is up?".
            2. **Response**: The app will display a response from Llama3.
            3. **Chat History**: Previous conversations will be shown on the app.

            ### Credits:
            - **Developer**: [Yiqiao Yin](https://www.y-yin.io/) | [App URL](https://huggingface.co/spaces/eagle0504/meta-llama) | [LinkedIn](https://www.linkedin.com/in/yiqiaoyin/) | [YouTube](https://youtube.com/YiqiaoYin/)

            Enjoy chatting with Meta's Llama3 model!
        """)

    # Example:
    st.success("Example: Explain what is supervised learning.")
    st.success("Example: What is large language model?")
    st.success("Example: How to conduct an AI experiment?")
    st.success("Example: Write a tensorflow flow code with a 3-layer neural network model.")


    # Add a button to clear the session state
    if st.button("Clear Session"):
        st.session_state.messages = []
        st.experimental_rerun()


# Initialize chat history
if "messages" not in st.session_state:
    st.session_state.messages = []


# Display chat messages from history on app rerun
for message in st.session_state.messages:
    with st.chat_message(message["role"]):
        st.markdown(message["content"])


# React to user input
if prompt := st.chat_input("πŸ˜‰ Ask any question or feel free to use the examples provided in the left sidebar."):

    # Display user message in chat message container
    st.chat_message("user").markdown(prompt)

    # Add user message to chat history
    st.session_state.messages.append({"role": "user", "content": prompt})

    # API Call
    response = call_llama(prompt)

    # Display assistant response in chat message container
    with st.chat_message("assistant"):
        st.markdown(response)
    # Add assistant response to chat history
    st.session_state.messages.append({"role": "assistant", "content": response})