Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,205 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import random
|
3 |
+
|
4 |
+
# Markdown data for insights
|
5 |
+
markdown_data = {
|
6 |
+
"python": """
|
7 |
+
### Python - Top 10 Code Tips ๐
|
8 |
+
|
9 |
+
1. **Use virtual environments**: Keep dependencies isolated with `venv` or `conda`. ๐ ๏ธ
|
10 |
+
2. **Utilize type hints**: Use Python's typing system for better code clarity and maintainability. ๐๏ธ
|
11 |
+
3. **Leverage list comprehensions**: Write cleaner, more efficient loops. ๐
|
12 |
+
4. **Avoid mutable default arguments**: Use `None` instead of mutable objects as function defaults. ๐ซ
|
13 |
+
5. **Use generators for large data**: Save memory with generator expressions and `yield`. ๐ก
|
14 |
+
6. **Understand the difference between `==` and `is`**: Use `is` for identity checks, `==` for equality. ๐
|
15 |
+
7. **Use `enumerate()`**: Replace traditional `for` loops when needing indices. ๐งฎ
|
16 |
+
8. **Try `dataclasses`**: Simplify class creation with Pythonโs `dataclass` decorator. ๐๏ธ
|
17 |
+
9. **Use `f-strings`**: Format strings efficiently using `f"{value}"`. โจ
|
18 |
+
10. **Write unit tests**: Test your functions with `unittest` or `pytest`. โ
|
19 |
+
""",
|
20 |
+
|
21 |
+
"streamlit": """
|
22 |
+
### Streamlit - Top 10 Code Tips ๐๏ธ
|
23 |
+
|
24 |
+
1. **Use `st.cache_data` for caching**: Cache expensive operations to speed up your app. โก
|
25 |
+
2. **Utilize the session state**: Store data between reruns with `st.session_state`. ๐
|
26 |
+
3. **Leverage components**: Integrate React components with `streamlit-component-template`. ๐งฉ
|
27 |
+
4. **Write custom widgets**: Expand functionality by creating custom Streamlit widgets. ๐ ๏ธ
|
28 |
+
5. **Use layout options**: Design better apps with `st.columns` and `st.expander`. ๐
|
29 |
+
6. **Use interactive sliders**: Create smooth user interactions with `st.slider()`. ๐๏ธ
|
30 |
+
7. **Handle forms properly**: Use `st.form()` for input forms to optimize reactivity. ๐
|
31 |
+
8. **Progress feedback**: Show progress with `st.progress()` and `st.spinner()`. ๐
|
32 |
+
9. **Embed HTML**: Enhance apps with `st.markdown()` using HTML inside markdown. ๐
|
33 |
+
10. **Deploy easily**: Use `streamlit.io` for one-click deployment. ๐
|
34 |
+
""",
|
35 |
+
|
36 |
+
"typescript": """
|
37 |
+
### TypeScript - Top 10 Code Tips ๐ป
|
38 |
+
|
39 |
+
1. **Use type annotations**: Always annotate variables and function return types. ๐
|
40 |
+
2. **Prefer interfaces over types**: Interfaces can be extended more easily than types. ๐ช
|
41 |
+
3. **Use union and intersection types**: Combine types in flexible ways with `|` and `&`. ๐ ๏ธ
|
42 |
+
4. **Utilize generics**: Write reusable functions and components with generics. ๐
|
43 |
+
5. **Avoid `any`**: Avoid using `any` type unless absolutely necessary. ๐ซ
|
44 |
+
6. **Leverage optional chaining**: Safely access deeply nested properties. โ
|
45 |
+
7. **Use `readonly` for immutability**: Enforce immutability with `readonly`. ๐
|
46 |
+
8. **Utilize `never` type**: Use `never` for unreachable code paths and exhaustive checks. ๐ง
|
47 |
+
9. **Understand narrowing**: Use control flow analysis to narrow down types. ๐งฎ
|
48 |
+
10. **Enable strict mode**: Always turn on strict mode for better type safety. ๐ก๏ธ
|
49 |
+
""",
|
50 |
+
|
51 |
+
"react_native": """
|
52 |
+
### React Native - Top 10 Code Tips ๐ฑ
|
53 |
+
|
54 |
+
1. **Use `StyleSheet`**: Organize and optimize styles with `StyleSheet.create`. ๐จ
|
55 |
+
2. **Avoid inline styles**: Use stylesheets for reusability and performance. ๐๏ธ
|
56 |
+
3. **Leverage Flexbox**: Design responsive layouts with Flexbox. ๐
|
57 |
+
4. **Handle platform-specific code**: Use `Platform` module for OS-specific logic. ๐ ๏ธ
|
58 |
+
5. **Optimize images**: Use `Image` and `ImageBackground` components efficiently. ๐ผ๏ธ
|
59 |
+
6. **Utilize hooks**: Use hooks like `useEffect` and `useState` for state management. ๐
|
60 |
+
7. **Use third-party libraries**: Incorporate libraries like `react-navigation` and `redux`. ๐
|
61 |
+
8. **Optimize for performance**: Avoid unnecessary re-renders using `React.memo` and `useCallback`. ๐๏ธ
|
62 |
+
9. **Handle gestures properly**: Use `react-native-gesture-handler` for gesture-based navigation. ๐ฒ
|
63 |
+
10. **Utilize TypeScript**: Combine React Native with TypeScript for safer code. ๐ป
|
64 |
+
""",
|
65 |
+
|
66 |
+
"libraries": """
|
67 |
+
### Top 10 Python Libraries for SVG, TypeScript, and React Components ๐ ๏ธ
|
68 |
+
|
69 |
+
1. **lxml**: Efficiently parse and manipulate XML, including SVG. ๐
|
70 |
+
2. **svgwrite**: Easily create and modify SVG files in Python. ๐ผ๏ธ
|
71 |
+
3. **CairosVG**: Convert SVG files to various formats like PNG. ๐
|
72 |
+
4. **pydantic**: Handle data validation and complex typing in TypeScript code generation. โ
|
73 |
+
5. **datamodel-code-generator**: Automatically generate TypeScript code from Python data models. ๐ป
|
74 |
+
6. **PyV8**: Run JavaScript code from within Python, useful for generating dynamic assets. ๐งโ๐ป
|
75 |
+
7. **transcrypt**: Compile Python code to JavaScript for use with TypeScript projects. ๐
|
76 |
+
8. **reactpy**: Build interactive UIs using Python for web and mobile (React-like). ๐ฒ
|
77 |
+
9. **react-native-svg**: Handle SVG assets in React Native applications. ๐
|
78 |
+
10. **streamlit-component-template**: Create custom React components inside Streamlit apps. ๐๏ธ
|
79 |
+
"""
|
80 |
+
}
|
81 |
+
|
82 |
+
# Set up the sidebar
|
83 |
+
st.sidebar.title("Insights on Technologies ๐ ๏ธ")
|
84 |
+
sections = ["Python Tips", "Streamlit Tips", "TypeScript Tips", "React Native Tips", "Python Libraries"]
|
85 |
+
selected_section = st.sidebar.selectbox("Choose a Section:", sections)
|
86 |
+
|
87 |
+
# Main content display
|
88 |
+
if selected_section == "Python Tips":
|
89 |
+
st.markdown(markdown_data["python"])
|
90 |
+
elif selected_section == "Streamlit Tips":
|
91 |
+
st.markdown(markdown_data["streamlit"])
|
92 |
+
elif selected_section == "TypeScript Tips":
|
93 |
+
st.markdown(markdown_data["typescript"])
|
94 |
+
elif selected_section == "React Native Tips":
|
95 |
+
st.markdown(markdown_data["react_native"])
|
96 |
+
elif selected_section == "Python Libraries":
|
97 |
+
st.markdown(markdown_data["libraries"])
|
98 |
+
|
99 |
+
# Tabs for interactive code examples
|
100 |
+
st.subheader("Interactive Code Examples ๐ป")
|
101 |
+
tabs = st.tabs(["Python", "Streamlit", "TypeScript", "React Native"])
|
102 |
+
|
103 |
+
# Example Python code generation
|
104 |
+
with tabs[0]:
|
105 |
+
st.markdown("""
|
106 |
+
**Example: Python Generating TypeScript** ๐จ
|
107 |
+
|
108 |
+
```python
|
109 |
+
def generate_typescript_button():
|
110 |
+
return '''
|
111 |
+
import React from 'react';
|
112 |
+
import { Button } from 'react-native';
|
113 |
+
|
114 |
+
interface ButtonProps {
|
115 |
+
title: string;
|
116 |
+
onPress: () => void;
|
117 |
+
}
|
118 |
+
|
119 |
+
const CustomButton: React.FC<ButtonProps> = ({ title, onPress }) => (
|
120 |
+
<Button title={title} onPress={onPress} />
|
121 |
+
);
|
122 |
+
|
123 |
+
export default CustomButton;
|
124 |
+
'''
|
125 |
+
```
|
126 |
+
""")
|
127 |
+
st.button("Generate TypeScript Code ๐๏ธ")
|
128 |
+
|
129 |
+
# Streamlit Example
|
130 |
+
with tabs[1]:
|
131 |
+
st.markdown("""
|
132 |
+
**Example: Custom Streamlit Widget** ๐๏ธ
|
133 |
+
|
134 |
+
```python
|
135 |
+
import streamlit as st
|
136 |
+
|
137 |
+
def custom_button(label):
|
138 |
+
st.write(f"Button: {label}")
|
139 |
+
if st.button(label):
|
140 |
+
st.write(f"Button {label} was clicked!")
|
141 |
+
|
142 |
+
custom_button("Click Me")
|
143 |
+
```
|
144 |
+
""")
|
145 |
+
st.button("Generate Streamlit Code ๐ป")
|
146 |
+
|
147 |
+
# TypeScript Example
|
148 |
+
with tabs[2]:
|
149 |
+
st.markdown("""
|
150 |
+
**Example: TypeScript Component in React Native** ๐ฑ
|
151 |
+
|
152 |
+
```typescript
|
153 |
+
import React from 'react';
|
154 |
+
import { View, Text, StyleSheet } from 'react-native';
|
155 |
+
|
156 |
+
const HelloWorld = () => (
|
157 |
+
<View style={styles.container}>
|
158 |
+
<Text style={styles.text}>Hello, World!</Text>
|
159 |
+
</View>
|
160 |
+
);
|
161 |
+
|
162 |
+
const styles = StyleSheet.create({
|
163 |
+
container: {
|
164 |
+
flex: 1,
|
165 |
+
justifyContent: 'center',
|
166 |
+
alignItems: 'center',
|
167 |
+
},
|
168 |
+
text: {
|
169 |
+
fontSize: 24,
|
170 |
+
color: 'blue',
|
171 |
+
},
|
172 |
+
});
|
173 |
+
|
174 |
+
export default HelloWorld;
|
175 |
+
```
|
176 |
+
""")
|
177 |
+
st.button("Generate React Native Code ๐ฒ")
|
178 |
+
|
179 |
+
# React Native Example
|
180 |
+
with tabs[3]:
|
181 |
+
st.markdown("""
|
182 |
+
**Example: React Native with TypeScript** ๐ป
|
183 |
+
|
184 |
+
```typescript
|
185 |
+
import React from 'react';
|
186 |
+
import { Text, View, Button } from 'react-native';
|
187 |
+
|
188 |
+
interface AppProps {
|
189 |
+
title: string;
|
190 |
+
}
|
191 |
+
|
192 |
+
const App: React.FC<AppProps> = ({ title }) => (
|
193 |
+
<View>
|
194 |
+
<Text>{title}</Text>
|
195 |
+
<Button title="Click Me" onPress={() => alert('Button Pressed!')} />
|
196 |
+
</View>
|
197 |
+
);
|
198 |
+
|
199 |
+
export default App;
|
200 |
+
```
|
201 |
+
""")
|
202 |
+
st.button("Generate Full React Native App ๐ฒ")
|
203 |
+
|
204 |
+
# Footer
|
205 |
+
st.sidebar.info("๐ Enjoy exploring Python, Streamlit, TypeScript, and React Native!")
|