Du Mingzhe commited on
Commit
58de0b5
·
1 Parent(s): 9abf55a
Files changed (1) hide show
  1. app.py +4 -94
app.py CHANGED
@@ -1,96 +1,6 @@
1
  import streamlit as st
2
- from streamlit_chat import message
3
- from streamlit.components.v1 import html
4
 
5
- def on_input_change():
6
- user_input = st.session_state.user_input
7
- st.session_state.past.append(user_input)
8
- st.session_state.generated.append("The messages from Bot\nWith new line")
9
-
10
- def on_btn_click():
11
- del st.session_state.past[:]
12
- del st.session_state.generated[:]
13
-
14
- audio_path = "https://docs.google.com/uc?export=open&id=16QSvoLWNxeqco_Wb2JvzaReSAw5ow6Cl"
15
- img_path = "https://www.groundzeroweb.com/wp-content/uploads/2017/05/Funny-Cat-Memes-11.jpg"
16
- youtube_embed = '''
17
- <iframe width="400" height="215" src="https://www.youtube.com/embed/LMQ5Gauy17k" title="YouTube video player" frameborder="0" allow="accelerometer; encrypted-media;"></iframe>
18
- '''
19
-
20
- markdown = """
21
- ### HTML in markdown is ~quite~ **unsafe**
22
- <blockquote>
23
- However, if you are in a trusted environment (you trust the markdown). You can use allow_html props to enable support for html.
24
- </blockquote>
25
-
26
- * Lists
27
- * [ ] todo
28
- * [x] done
29
-
30
- Math:
31
-
32
- Lift($L$) can be determined by Lift Coefficient ($C_L$) like the following
33
- equation.
34
-
35
- $$
36
- L = \\frac{1}{2} \\rho v^2 S C_L
37
- $$
38
-
39
- ~~~py
40
- import streamlit as st
41
-
42
- st.write("Python code block")
43
- ~~~
44
-
45
- ~~~js
46
- console.log("Here is some JavaScript code")
47
- ~~~
48
-
49
- """
50
-
51
- table_markdown = '''
52
- A Table:
53
-
54
- | Feature | Support |
55
- | ----------: | :------------------- |
56
- | CommonMark | 100% |
57
- | GFM | 100% w/ `remark-gfm` |
58
- '''
59
-
60
- st.session_state.setdefault(
61
- 'past',
62
- ['plan text with line break',
63
- 'play the song "Dancing Vegetables"',
64
- 'show me image of cat',
65
- 'and video of it',
66
- 'show me some markdown sample',
67
- 'table in markdown']
68
- )
69
- st.session_state.setdefault(
70
- 'generated',
71
- [{'type': 'normal', 'data': 'Line 1 \n Line 2 \n Line 3'},
72
- {'type': 'normal', 'data': f'<audio controls src="{audio_path}"></audio>'},
73
- {'type': 'normal', 'data': f'<img width="100%" height="200" src="{img_path}"/>'},
74
- {'type': 'normal', 'data': f'{youtube_embed}'},
75
- {'type': 'normal', 'data': f'{markdown}'},
76
- {'type': 'table', 'data': f'{table_markdown}'}]
77
- )
78
-
79
- st.title("Chat placeholder")
80
-
81
- chat_placeholder = st.empty()
82
-
83
- with chat_placeholder.container():
84
- for i in range(len(st.session_state['generated'])):
85
- message(st.session_state['past'][i], is_user=True, key=f"{i}_user")
86
- message(
87
- st.session_state['generated'][i]['data'],
88
- key=f"{i}",
89
- allow_html=True,
90
- is_table=True if st.session_state['generated'][i]['type']=='table' else False
91
- )
92
-
93
- st.button("Clear message", on_click=on_btn_click)
94
-
95
- with st.container():
96
- st.text_input("User Input:", on_change=on_input_change, key="user_input")
 
1
  import streamlit as st
2
+ import numpy as np
 
3
 
4
+ with st.chat_message("assistant"):
5
+ st.write("Hello human")
6
+ st.bar_chart(np.random.randn(30, 3))