Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,24 @@
|
|
1 |
from transformers import pipeline
|
2 |
import streamlit as st
|
3 |
|
4 |
-
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
-
|
8 |
-
|
|
|
|
|
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')
|