AAhad commited on
Commit
ab8af5c
·
verified ·
1 Parent(s): 1d5dd2f

updated with Chat LLM

Browse files
Files changed (1) hide show
  1. app.py +42 -18
app.py CHANGED
@@ -1,19 +1,43 @@
1
  import streamlit as st
2
- import pandas as pd
3
-
4
- st.write("Here's our first attempt at using data to create a table:")
5
- st.write(pd.DataFrame({
6
- 'first column': [1, 2, 3, 4],
7
- 'second column': [10, 20, 30, 40]
8
- }))
9
-
10
- DATE_COLUMN = 'date/time'
11
- DATA_URL = ('https://s3-us-west-2.amazonaws.com/'
12
- 'streamlit-demo-data/uber-raw-data-sep14.csv.gz')
13
-
14
- def load_data(nrows):
15
- data = pd.read_csv(DATA_URL, nrows=nrows)
16
- lowercase = lambda x: str(x).lower()
17
- data.rename(lowercase, axis='columns', inplace=True)
18
- data[DATE_COLUMN] = pd.to_datetime(data[DATE_COLUMN])
19
- return data
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ import random
3
+ import time
4
+
5
+
6
+ # Streamed response emulator
7
+ def response_generator():
8
+ response = random.choice(
9
+ [
10
+ "Hello there! How can I assist you today?",
11
+ "Hi, human! Is there anything I can help you with?",
12
+ "Do you need help?",
13
+ ]
14
+ )
15
+ for word in response.split():
16
+ yield word + " "
17
+ time.sleep(0.05)
18
+
19
+
20
+ st.title("My Simple chat LLM")
21
+
22
+ # Initialize chat history
23
+ if "messages" not in st.session_state:
24
+ st.session_state.messages = []
25
+
26
+ # Display chat messages from history on app rerun
27
+ for message in st.session_state.messages:
28
+ with st.chat_message(message["role"]):
29
+ st.markdown(message["content"])
30
+
31
+ # Accept user input
32
+ if prompt := st.chat_input("What is up?"):
33
+ # Add user message to chat history
34
+ st.session_state.messages.append({"role": "user", "content": prompt})
35
+ # Display user message in chat message container
36
+ with st.chat_message("user"):
37
+ st.markdown(prompt)
38
+
39
+ # Display assistant response in chat message container
40
+ with st.chat_message("assistant"):
41
+ response = st.write_stream(response_generator())
42
+ # Add assistant response to chat history
43
+ st.session_state.messages.append({"role": "assistant", "content": response})