Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2025,3 +2025,82 @@ if showExtendedTextInterface:
|
|
| 2025 |
num_columns_text=st.slider(key="num_columns_text", label="Choose Number of Text Columns", min_value=1, max_value=15, value=4)
|
| 2026 |
display_buttons_with_scores(num_columns_text) # Feedback Jump Grid
|
| 2027 |
st.markdown(personality_factors)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2025 |
num_columns_text=st.slider(key="num_columns_text", label="Choose Number of Text Columns", min_value=1, max_value=15, value=4)
|
| 2026 |
display_buttons_with_scores(num_columns_text) # Feedback Jump Grid
|
| 2027 |
st.markdown(personality_factors)
|
| 2028 |
+
|
| 2029 |
+
|
| 2030 |
+
|
| 2031 |
+
|
| 2032 |
+
import streamlit as st
|
| 2033 |
+
import os
|
| 2034 |
+
import importlib.util
|
| 2035 |
+
|
| 2036 |
+
def run_py_file(file_path):
|
| 2037 |
+
"""🏃♂️ Run a Python file and return its output"""
|
| 2038 |
+
spec = importlib.util.spec_from_file_location("module.name", file_path)
|
| 2039 |
+
module = importlib.util.module_from_spec(spec)
|
| 2040 |
+
spec.loader.exec_module(module)
|
| 2041 |
+
return getattr(module, 'output', None)
|
| 2042 |
+
|
| 2043 |
+
def recursive_file_search(directory):
|
| 2044 |
+
"""🔍 Recursively search for .py files in a directory"""
|
| 2045 |
+
for root, dirs, files in os.walk(directory):
|
| 2046 |
+
for file in files:
|
| 2047 |
+
if file.endswith('.py'):
|
| 2048 |
+
yield os.path.join(root, file)
|
| 2049 |
+
|
| 2050 |
+
def save_component(name, content, file_type):
|
| 2051 |
+
"""💾 Save a component to a file"""
|
| 2052 |
+
directory = f"components/{file_type}"
|
| 2053 |
+
os.makedirs(directory, exist_ok=True)
|
| 2054 |
+
with open(f"{directory}/{name}.{file_type}", "w") as f:
|
| 2055 |
+
f.write(content)
|
| 2056 |
+
|
| 2057 |
+
def load_component(name, file_type):
|
| 2058 |
+
"""📂 Load a component from a file"""
|
| 2059 |
+
try:
|
| 2060 |
+
with open(f"components/{file_type}/{name}.{file_type}", "r") as f:
|
| 2061 |
+
return f.read()
|
| 2062 |
+
except FileNotFoundError:
|
| 2063 |
+
return None
|
| 2064 |
+
|
| 2065 |
+
def main():
|
| 2066 |
+
st.title("AI-Generated Component Manager")
|
| 2067 |
+
|
| 2068 |
+
# Run all Python files in the directory
|
| 2069 |
+
for py_file in recursive_file_search("."):
|
| 2070 |
+
output = run_py_file(py_file)
|
| 2071 |
+
if output:
|
| 2072 |
+
st.write(f"Output from {py_file}:", output)
|
| 2073 |
+
|
| 2074 |
+
# Component management
|
| 2075 |
+
component_type = st.selectbox("Select component type", ["react", "typescript"])
|
| 2076 |
+
component_name = st.text_input("Component name")
|
| 2077 |
+
component_content = st.text_area("Component content")
|
| 2078 |
+
|
| 2079 |
+
if st.button("Save Component"):
|
| 2080 |
+
save_component(component_name, component_content, component_type)
|
| 2081 |
+
st.success(f"Saved {component_type} component: {component_name}")
|
| 2082 |
+
|
| 2083 |
+
if st.button("Load Component"):
|
| 2084 |
+
loaded_content = load_component(component_name, component_type)
|
| 2085 |
+
if loaded_content:
|
| 2086 |
+
st.code(loaded_content, language=component_type)
|
| 2087 |
+
else:
|
| 2088 |
+
st.error(f"Component {component_name} not found")
|
| 2089 |
+
|
| 2090 |
+
# Display components using Streamlit's components
|
| 2091 |
+
st.components.v1.html(
|
| 2092 |
+
f"""
|
| 2093 |
+
<div id="react-root"></div>
|
| 2094 |
+
<script src="https://unpkg.com/react@17/umd/react.development.js"></script>
|
| 2095 |
+
<script src="https://unpkg.com/react-dom@17/umd/react-dom.development.js"></script>
|
| 2096 |
+
<script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
|
| 2097 |
+
<script type="text/babel">
|
| 2098 |
+
// Load and render components here
|
| 2099 |
+
ReactDOM.render(<div>Custom Component</div>, document.getElementById('react-root'));
|
| 2100 |
+
</script>
|
| 2101 |
+
""",
|
| 2102 |
+
height=300,
|
| 2103 |
+
)
|
| 2104 |
+
|
| 2105 |
+
if __name__ == "__main__":
|
| 2106 |
+
main()
|