Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,19 +3,30 @@ import streamlit as st
|
|
3 |
from gradio_client import Client
|
4 |
|
5 |
client = Client("https://b2e7dc20663679013e.gradio.live/")
|
|
|
6 |
|
7 |
-
def chat_app():
|
8 |
-
st.title('Digital Ink')
|
9 |
-
#chat input field with placeholder
|
10 |
-
user_input = st.chat_input('Ask Digital Ink...')
|
11 |
-
#handle user input
|
12 |
-
if user_input:
|
13 |
-
#using gradio api client to generate response
|
14 |
-
response = client.predict(
|
15 |
-
user_input,
|
16 |
-
api_name="/predict"
|
17 |
-
)
|
18 |
-
st.chat_message('Digital Ink', response)
|
19 |
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
from gradio_client import Client
|
4 |
|
5 |
client = Client("https://b2e7dc20663679013e.gradio.live/")
|
6 |
+
st.title('Digital Ink')
|
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
+
|
10 |
+
# Initialize chat history
|
11 |
+
if "messages" not in st.session_state:
|
12 |
+
st.session_state.messages = []
|
13 |
+
|
14 |
+
# Display chat messages from history
|
15 |
+
for message in st.session_state.messages:
|
16 |
+
with st.chat_message(message["role"]):
|
17 |
+
st.markdown(message["content"])
|
18 |
+
|
19 |
+
def get_response(prompt):
|
20 |
+
#using gradio api client to generate response
|
21 |
+
response = client.predict(prompt,api_name="/predict")
|
22 |
+
return response
|
23 |
+
|
24 |
+
# User input
|
25 |
+
if prompt := st.chat_input("Ask Digital Ink..."):
|
26 |
+
# Display user message in chat message container
|
27 |
+
with st.chat_message("user"):
|
28 |
+
st.markdown(prompt)
|
29 |
+
# Generate and display assistant response in chat message container
|
30 |
+
with st.chat_message("assistant"):
|
31 |
+
response = get_response(prompt)
|
32 |
+
st.markdown(response)
|