Skip to content

Commit

Permalink
work in progress for sharing
Browse files Browse the repository at this point in the history
  • Loading branch information
mike dupont committed Sep 17, 2023
1 parent 1d470e0 commit f3876c8
Show file tree
Hide file tree
Showing 34 changed files with 751 additions and 653 deletions.
2 changes: 1 addition & 1 deletion Hackathon.org
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
* Tasks
b* Tasks
We will now use org mode as our input for the task system

** Task1
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
test3:
python ./src/streamlit_app.py
test2:
git cat-file --batch --batch-all-objects -p > all2.txt

Expand Down
6 changes: 6 additions & 0 deletions src/introspector/act.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

def act(data):
if not data:
return
for data1 in data:
yield from doapply(data1) # apply those changes to the api
26 changes: 26 additions & 0 deletions src/introspector/app_args.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import streamlit as st

# globals
app_args = {}
oparams = st.experimental_get_query_params()
params = {
x: oparams[x][0] for x in oparams
}

def get_mode():
return app_args['mode']

def get_concept_id():
return app_args['concept_id']

def get_input_id():
return app_args['input_id']

def get_last_id():
return app_args['last_id']

def get_app_id():
return app_args['app_id']

def get_page_size():
return app_args['page_size']
21 changes: 21 additions & 0 deletions src/introspector/clarifai_login.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
PAT = st.secrets["CLARIFAI_PAT"]
USER_ID =st.secrets["clarifai_user_id"]
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
user_metadata = (('authorization', 'Key ' + PAT),)
os.environ["CLARIFAI_PAT"] = st.secrets["CLARIFAI_PAT"]
client = User(user_id=st.secrets["clarifai_user_id"])
userDataObject= None

# taken from https://gist.githubusercontent.com/iankelk/7e46c9935442ba01853b1689ff4a5038/raw/a261f99e6dd9cef6cc3d9ee04648df40232072d9/C-everything.py
def load_pat():
if "CLARIFAI_PAT" not in st.secrets:
st.error("You need to set the CLARIFAI_PAT in the secrets.")
st.stop()
return st.secrets.CLARIFAI_PAT

def get_userDataObject():
global userDataObject
if userDataObject is None:
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=get_app_id())
return userDataObject
23 changes: 23 additions & 0 deletions src/introspector/columns.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import streamlit as st

(col1,col_concept,col_workflow,col2) = st.columns(4)

# with col1:
# #aapp_args["mode"] = st.text_input("Mode", help="Mode to use", key="mode",value=params.get("mode","concept-inputs"))
# app_args["app_id"] = st.text_input("app_id", help="id" , value ="Introspector-LLama2-Hackathon-Demo1")
# app_args["input_id"] = st.text_ainput(

# with col_4:
# page_size = st.number_input("Page Size", min_value=1,key="page_size",
# help="Use a number input widget to allow users to specify the page size. This will control how many items are displayed per page",
# value=int(params.get("page_size", "3")))

# with col_workflows:
# app_args["workflow"] = st.text_input(
# "Workflow",
# value=params.get(
# "workflow",
# "RakeItUpV3Critical_Reconstruction_of4"),
# key="workflow"
# )

14 changes: 14 additions & 0 deletions src/introspector/concepts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from .app_args import get_concept_id,params,app_args
from .columns import col_concept
import streamlit as st
def get_concept_id():
return app_args['concept_id']
def get_inputs():
with col_concept:
app_args["concept_id"] = st.text_input(
"Concept ID",
key = "concept_id",
help = "Concept id to search for" ,
value = params.get("concept_id","python")
)
return get_concept_id()
9 changes: 9 additions & 0 deletions src/introspector/datasets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def datasets(app):
if app.name in app_datasets:
st.write ("DEBUG1",app.name)
for name in app_datasets[app.name]:
st.write ("DEBUG2",app.name, "in", app_datasets)
yield name
else:
#st.write ("DEBUG",app.name, "not in", app_datasets)
pass
116 changes: 116 additions & 0 deletions src/introspector/debug.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@

##inject code

#if not os.path.exists(target):
# os.mkdir(target)

#ctx =streamlit.runtime.scriptrunner.script_runner.get_script_run_ctx()

# st.write("CTX",ctx)
# st.write("CTX",str(ctx))
# st.write("Sess",dir(ctx))
# for x in dir(ctx):
# st.write("DEBUG",x,getattr(ctx,x,"None"))


# ctxScriptRunContextScriptRunContext(session_id='6ab6368d-3bf6-492e-a2d0-d8d3a5733e71', _enqueue=<bound method ScriptRunner._enqueue_forward_msg of ScriptRunner(_session_id='6ab6368d-3bf6-492e-a2d0-d8d3a5733e71', _main_script_path='./src/streamlit_app.py', _uploaded_file_mgr=MemoryUploadedFileManager(endpoint='/_stcore...
# A context object that contains data for a "script run" - that is,
# data that's scoped to a single ScriptRunner execution (and therefore also
# scoped to a single connected "session").

# ScriptRunContext is used internally by virtually every `st.foo()` function.
# It is accessed only from the script thread that's created by ScriptRunner.

# Streamlit code typically retrieves the active ScriptRunContext via the
# `get_script_run_ctx` function.
# command_tracking_deactivatedbool True
# cursorsdict {}
# dg_stacklist []
# form_ids_this_runset set()
# gather_usage_statsbool True
# page_script_hashstr '04d9c6d3425fdb18dfa2143151c97767'
# query_stringstr ''
# session_idstr '6ab6368d-3bf6-492e-a2d0-d8d3a5733e71'
# session_stateSafeSessionState Thread-safe wrapper around SessionState.
# tracked_commandslist [name: "write" args { k: "1" t: "streamlit.runtime.scriptrunner.script_run_context.ScriptRunContext" p: 1 } ]
# tracked_commands_counterCounter Counter({'write': 1})
# uploaded_file_mgrMemoryUploadedFileManager MemoryUploadedFileManager(endpoint='/_stcore/upload_file')
# user_infodict {'email': 'test@localhost.com'}
# widget_ids_this_runset set()
# widget_user_keys_this_runset set()
# enqueuemethod Enqueue a ForwardMsg for this context's session.
# on_script_startmethod No docs available
# resetmethod No docs available
# ScriptRunContext(session_id='6ab6368d-3bf6-492e-a2d0-d8d3a5733e71', _enqueue=<bound method ScriptRunner._enqueue_forward_msg of ScriptRunner(_session_id='6ab6368d-3bf6-492e-a2d0-d8d3a5733e71', _main_script_path='./src/streamlit_app.py', _uploaded_file_mgr=MemoryUploadedFileManager(endpoint='/_stcore/upload_file'), _script_cache=<streamlit.runtime.scriptrunner.script_cache.ScriptCache object at 0x7f305f154d90>, _user_info={'email': 'test@localhost.com'}, _client_state=, _session_state=<streamlit.runtime.state.safe_session_state.SafeSessionState object at 0x7f305cc78670>, _requests=<streamlit.runtime.scriptrunner.script_requests.ScriptRequests object at 0x7f304dc0b2e0>, on_event=<blinker.base.Signal object at 0x7f304dc0ba30>, _execing=True, _script_thread=<Thread(ScriptRunner.scriptThread, started 139845467305536)>)>, query_string='', session_state=<streamlit.runtime.state.safe_session_state.SafeSessionState object at 0x7f305cc78670>, uploaded_file_mgr=MemoryUploadedFileManager(endpoint='/_stcore/upload_file'), page_script_hash='04d9c6d3425fdb18dfa2143151c97767', user_info={'email': 'test@localhost.com'}, gather_usage_stats=True, command_tracking_deactivated=False, tracked_commands=[name: "write" args { k: "1" t: "streamlit.runtime.scriptrunner.script_run_context.ScriptRunContext" p: 1 } time: 5345 ], tracked_commands_counter=Counter({'write': 1}), _set_page_config_allowed=False, _has_script_started=True, widget_ids_this_run=set(), widget_user_keys_this_run=set(), form_ids_this_run=set(), cursors={0: RunningCursor(_parent_path=(), _index=1)}, dg_stack=[])

#st.write("Sess STate",ctx.session_state._state)
#st.write("Sess STate",dir(ctx.session_state._state))
#st.write("Sess",dir(ctx.session_state))


values = {}


#st.write("current",tornado.ioloop.IOLoop.current())

#import pdb
#pdb.set_trace()

# for x in inspect.stack():
# st.write("CALLBACK",str(x))
# #st.write(dir(x))
# st.write("CALLBACK1",x.frame)
# st.write("CALLBACK2",x.frame.f_globals)
# st.write("CALLBACK3",x.code_context)

#for line in traceback.format_stack():
# st.write(line.strip())
# st.write(line)

_io_loops= {}
_io_loop = tornado.ioloop.IOLoop.current()
#st.write("current",type(_io_loop).__name__)
if _io_loop not in _io_loops:
_io_loops[_io_loop] = True
#st.write("started ")

asyncio_loop = _io_loop.asyncio_loop # type: ignore

#st.write("asyncio_loop ",asyncio_loop)
tasks = asyncio.all_tasks(asyncio_loop) # type: ignore

asyncio_loop.set_debug(True)
#for x in dir(asyncio_loop):
# st.write(x)
#st.write("asyncio_loop tasks", tasks)
#if hasattr(asyncio, "all_tasks"): # py37

# else:
# tasks = asyncio.Task.all_tasks(asyncio_loop)


#modify_times = {} # type: Dict[str, float]
#callback = functools.partial(_reload_on_update, modify_times)
#scheduler = ioloop.PeriodicCallback(callback, check_time)
#scheduler.start()


# for x in list(globals()):
# v = globals()[x]

# if isinstance(v, types.ModuleType):
# values[x] = globals()[x]


st.write("server")
#st.dataframe(dir(streamlit.web.server.server))
for module in values:
st.write(module)
#st.write(help(module))
#for x in values[module]:
# v = values[module][x]
# st.write(module,x,v)
#st.dataframe(dir(module))

#st.dataframe(dir(streamlit))

17 changes: 17 additions & 0 deletions src/introspector/decide.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
def decide(data):
if data:
if not hasattr(data, '__iter__'):
#st.write("The object is iterable.")
if not isinstance(data, Iterable):
#st.write("The object is iterable.")
#else:
name = ""
if hasattr(data,"name"):
name = data.name()

data = [ "Just " + name + str(type(data)) + " debug "+ str(data) ]
yield myselect(data) # let the user select which ones
return

#for data1 in data:
yield from myselect([data1 for data1 in data]) # let the user select which ones
13 changes: 13 additions & 0 deletions src/introspector/do_apply.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# from https://docs.streamlit.io/knowledge-base/deploy/authentication-without-sso
def doapply(data):
for x in data:
if isinstance(x,str):
st.write("apply",x)
yield x
else:
if hasattr(x,"apply"):
yield from x.apply()
else:
st.write("do apply other",x)
yield x

20 changes: 20 additions & 0 deletions src/introspector/filtering.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
def filtering(data):
if isinstance(data,str):
yield data
return
if isinstance(data, Iterable):

if isinstance(data, types.GeneratorType):
pass
else:

if "value" in data:
v = data["value"]
#st.write("VALUE",v)
else:
st.write("Filtering Object is iterable",type(data).__name__,data)
for x in data:
yield x
else:
st.write("Filtering Object not an iterable", data)
yield data
60 changes: 60 additions & 0 deletions src/introspector/find_inputs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
from app_args
def find_inputs(concept_id):
max_count = get_page_size()
user_app_id=get_userDataObject()
st.write("search for concepts",concept_id)
st.write("user data",user_app_id)
#st.write("stub",stub)
#st.write("user metadata",user_metadata)
post_annotations_searches_response = stub.PostAnnotationsSearches(
service_pb2.PostAnnotationsSearchesRequest(
user_app_id=user_app_id,
searches = [
resources_pb2.Search(
query=resources_pb2.Query(
filters=[
resources_pb2.Filter(
annotation=resources_pb2.Annotation(
data=resources_pb2.Data(
concepts=[ # You can search by multiple concepts
resources_pb2.Concept(
id=concept_id, # You could search by concept Name as well
value=1 # Value of 0 will search for images that don't have the concept
)
]
)
)
)
]
)
)
]
),
metadata=user_metadata
)

if post_annotations_searches_response.status.code != status_code_pb2.SUCCESS:
st.write("Post searches failed, status: " + post_annotations_searches_response.status.description)


count = 0
for hit in post_annotations_searches_response.hits:
value = str(hit)
for x in hit.ListFields():
for y in x:
if isinstance(y, resources_pb2.Input):
input_object = y
data2 = requests.get(input_object.data.text.url)
value = data2.text
count = count +1
if count < max_count:
dt = {
"type": "input",
"id": input_object.id,
"url": input_object.data.text.url,
"value": value
}
st.write(dt)
yield(dt)
else:
return #leave
Empty file added src/introspector/get_args.py
Empty file.
Loading

0 comments on commit f3876c8

Please sign in to comment.