awacke1 commited on
Commit
faed411
ยท
verified ยท
1 Parent(s): 1992e97

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +205 -0
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!")