Spaces:
Running
Running
File size: 3,408 Bytes
3157f2b 5bd77b5 8bb6bcc 4b990c7 633033e 7f1aca2 4766680 8f8fa63 5710bd9 f39a294 5201e45 96f874d 027697d 5201e45 96f874d 027697d f39a294 96f874d 027697d 3157f2b 96f874d 628bb6f 731de2f 628bb6f e16c1f3 7b64b2c 7d34933 027697d 8357dbc cad848a 06ed65c 5839ded 06ed65c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# Based on the following code demo: https://github.com/google-research/tensorflow-coder/blob/master/tf_coder/tf_coder_main.py
import streamlit as st
from tf_coder.value_search import colab_interface, value_search_settings
from streamlit_ace import st_ace
st.set_page_config(page_title="TensorFlow Coder", page_icon='π©βπ»', layout="wide")
st.title("π©βπ» TensorFlow Coder")
st.write('#')
st.write("[TensorFlow Coder](https://github.com/google-research/tensorflow-coder) is a program synthesis tool developed at Google Research by Kensen Shi, David Bieber and Rishabh Singh. It takes an example input-output tensor example and attempts to find the combination of TensorFlow ops that capture that transformation. Please cite the authors' [paper](https://github.com/google-research/tensorflow-coder/blob/master/README.md#citation) if you use their tool in your work. Also checkout the TensorFlow [Blog post](https://blog.tensorflow.org/2020/08/introducing-tensorflow-coder-tool.html) for more information and examples.")
col1, col2, col3 = st.columns([5, 5, 3])
with col1:
st.write('#### Inputs')
inputs = st_ace(placeholder="The input tensor(s) specified as a dictionary", value="{'rows': [10, 20, 30],\n'cols': [1,2,3,4]}", language="python", theme="solarized_dark", auto_update=True)
with col2:
st.write('#### Output')
output = st_ace(placeholder="The output tensor", value="[[11, 12, 13, 14],\n[21, 22, 23, 24],\n[31, 32, 33, 34]]", language="python", theme="solarized_dark", auto_update=True)
with col3:
st.write('#### Constants')
constants = st_ace(placeholder="Optional list of scalar constants", value="[]", language="python", theme="solarized_dark", auto_update=True)
st.write("#### Description")
description = st.text_input(label="", placeholder="An optional natural language description of the operation", value="add two vectors with broadcasting to get a matrix")
with st.expander("βοΈ Search Options", expanded=False):
settings_kwargs = dict()
settings_kwargs["require_all_inputs_used"] = st.checkbox("Require All Inputs", value=True)
settings_kwargs["only_minimal_solutions"] = st.checkbox("Only Minimal Solutions", value=False)
settings_kwargs["max_solutions"] = st.slider("Maximum number of solutions", value=1, min_value=1, step=1, max_value=256)
settings_kwargs["timeout"] = st.slider("Timeout in seconds", value=300, min_value=1, step=10, max_value=300)
if st.button("π Search for Tensor Ops!"):
i = eval(inputs)
o = eval(output)
c = eval(constants)
settings = value_search_settings.from_dict({
'timeout': settings_kwargs["timeout"],
'only_minimal_solutions': settings_kwargs["only_minimal_solutions"],
'max_solutions': settings_kwargs["max_solutions"],
'require_all_inputs_used': settings_kwargs["require_all_inputs_used"],
'require_one_input_used': not settings_kwargs["require_all_inputs_used"],
})
with st.spinner("Searching for solution..."):
results = colab_interface.run_value_search_from_colab(i, o, c, description, settings)
num_solutions = len(results.solutions)
solution_solutions = " solutions" if num_solutions > 1 else " solution"
st.write(f"Found {num_solutions}{solution_solutions} in {results.total_time:.2f} seconds")
for solution in results.solutions:
st.code(solution.expression, language='python') |