Spaces:
Sleeping
Sleeping
Commit
·
f483191
1
Parent(s):
b3ac895
Create sampleApp.py
Browse files- sampleApp.py +38 -0
sampleApp.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""
|
| 3 |
+
Created on Thu Sep 21 22:17:43 2023
|
| 4 |
+
|
| 5 |
+
@author: Loges
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
import streamlit as st
|
| 9 |
+
|
| 10 |
+
st.set_page_config(page_title='Sample Chatbot', layout='wide')
|
| 11 |
+
|
| 12 |
+
if 'messages' not in st.session_state:
|
| 13 |
+
st.session_state.messages=[]
|
| 14 |
+
|
| 15 |
+
st.subheader("Sample Chatbot")
|
| 16 |
+
|
| 17 |
+
for message in st.session_state.messages:
|
| 18 |
+
with st.chat_message(message['role']):
|
| 19 |
+
st.markdown(message['content'])
|
| 20 |
+
|
| 21 |
+
## messages element format: {'role':'user', 'content':'<user prompt>'}
|
| 22 |
+
|
| 23 |
+
if prompt:=st.chat_input("What is up!"):
|
| 24 |
+
with st.chat_message("user"):
|
| 25 |
+
st.markdown(prompt)
|
| 26 |
+
|
| 27 |
+
st.session_state.messages.append({
|
| 28 |
+
'role':'user',
|
| 29 |
+
'content': prompt})
|
| 30 |
+
|
| 31 |
+
response = f"Echo: {prompt}"
|
| 32 |
+
|
| 33 |
+
with st.chat_message("assistant"):
|
| 34 |
+
st.markdown(response)
|
| 35 |
+
|
| 36 |
+
st.session_state.messages.append({
|
| 37 |
+
'role':'assistant',
|
| 38 |
+
'content': response})
|