h1r41 commited on
Commit
c330d26
1 Parent(s): a272c58

initial commit

Browse files
Files changed (2) hide show
  1. requirements.txt +0 -0
  2. streamlit_app.py +49 -0
requirements.txt ADDED
Binary file (3.39 kB). View file
 
streamlit_app.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from llama_cpp import Llama
2
+ import streamlit as st
3
+
4
+ model_path = "vicuna-13b-v1.5.ggmlv3.q2_K.bin"
5
+ llama = Llama(model_path)
6
+
7
+ def generate_response(messages: list) -> str:
8
+ response = llama.create_chat_completion(messages, max_tokens=-1, stream=False)
9
+ print(f"response: {response}")
10
+ return response['choices'][0]['message']['content']
11
+
12
+ def main():
13
+ st.title("Chat with Vicuna!")
14
+
15
+ # Session state for retaining messages
16
+ if 'messages' not in st.session_state:
17
+ st.session_state.messages = []
18
+
19
+ # Display chat messages from history on app rerun
20
+ for message in st.session_state.messages:
21
+ with st.chat_message(message["role"]):
22
+ st.markdown(f"{message['content']}")
23
+
24
+ # Input for the user message
25
+ user_message = st.chat_input("Your Message")
26
+
27
+ # React to user input
28
+ if user_message:
29
+ # Display user message in chat message container
30
+ with st.chat_message("user"):
31
+ st.markdown(f"{user_message}")
32
+ # Add user message to chat history
33
+ st.session_state.messages.append({"role": "user", "content": user_message})
34
+
35
+ with st.chat_message("assistant"):
36
+ message_placeholder = st.empty()
37
+ full_response = ""
38
+
39
+ for char in generate_response([{"role": m["role"], "content": m["content"]} for m in st.session_state.messages]):
40
+ full_response += char
41
+ message_placeholder.markdown(full_response + "❙")
42
+
43
+ message_placeholder.markdown(full_response)
44
+
45
+ st.session_state.messages.append({"role": "assistant", "content": full_response})
46
+
47
+
48
+ if __name__ == "__main__":
49
+ main()