miwojc commited on
Commit
5861710
1 Parent(s): af34499

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -4
app.py CHANGED
@@ -1,11 +1,24 @@
1
  from transformers import pipeline
2
  import streamlit as st
3
 
4
- # if 'user_text' not in st.session_state:
5
- # st.session_state.user_text = 'foo'
 
 
 
 
 
 
 
 
 
 
 
6
 
7
- # st.text_input("Write something", value=st.session_state.user_text)
8
- st.text_input("Write something")
 
 
9
 
10
  if st.button("Write with transformer"):
11
  gpt2 = pipeline('text-generation')
 
1
  from transformers import pipeline
2
  import streamlit as st
3
 
4
+ from streamlit.report_thread import get_report_ctx
5
+ def query_cache(q_emb=None):
6
+ ctx = get_report_ctx()
7
+ session_id = ctx.session_id
8
+ session = st.server.server.Server.get_current()._get_session_info(session_id).session
9
+ if not hasattr(session, "_query_state"):
10
+ setattr(session, "_query_state", q_emb)
11
+ if q_emb:
12
+ session._query_state = q_emb
13
+ return session._query_state
14
+ # usage
15
+ q_emb = query_cache() # will get from cache if exists
16
+ #q_emb = query_cache(new_emb) # will set cache to value
17
 
18
+ if 'user_text' not in q_emb:
19
+ q_emb.user_text = 'foo'
20
+
21
+ st.text_input("Write something", value=q_emb.user_text)
22
 
23
  if st.button("Write with transformer"):
24
  gpt2 = pipeline('text-generation')