awacke1's picture
Create app.py
faed411 verified
import streamlit as st
import random
# Markdown data for insights
markdown_data = {
"python": """
### Python - Top 10 Code Tips ๐Ÿ
1. **Use virtual environments**: Keep dependencies isolated with `venv` or `conda`. ๐Ÿ› ๏ธ
2. **Utilize type hints**: Use Python's typing system for better code clarity and maintainability. ๐Ÿ–‹๏ธ
3. **Leverage list comprehensions**: Write cleaner, more efficient loops. ๐ŸŒ€
4. **Avoid mutable default arguments**: Use `None` instead of mutable objects as function defaults. ๐Ÿšซ
5. **Use generators for large data**: Save memory with generator expressions and `yield`. ๐Ÿ’ก
6. **Understand the difference between `==` and `is`**: Use `is` for identity checks, `==` for equality. ๐Ÿ”
7. **Use `enumerate()`**: Replace traditional `for` loops when needing indices. ๐Ÿงฎ
8. **Try `dataclasses`**: Simplify class creation with Pythonโ€™s `dataclass` decorator. ๐Ÿ—๏ธ
9. **Use `f-strings`**: Format strings efficiently using `f"{value}"`. โœจ
10. **Write unit tests**: Test your functions with `unittest` or `pytest`. โœ…
""",
"streamlit": """
### Streamlit - Top 10 Code Tips ๐ŸŽ›๏ธ
1. **Use `st.cache_data` for caching**: Cache expensive operations to speed up your app. โšก
2. **Utilize the session state**: Store data between reruns with `st.session_state`. ๐Ÿ”„
3. **Leverage components**: Integrate React components with `streamlit-component-template`. ๐Ÿงฉ
4. **Write custom widgets**: Expand functionality by creating custom Streamlit widgets. ๐Ÿ› ๏ธ
5. **Use layout options**: Design better apps with `st.columns` and `st.expander`. ๐Ÿ“
6. **Use interactive sliders**: Create smooth user interactions with `st.slider()`. ๐ŸŽš๏ธ
7. **Handle forms properly**: Use `st.form()` for input forms to optimize reactivity. ๐Ÿ“„
8. **Progress feedback**: Show progress with `st.progress()` and `st.spinner()`. ๐Ÿ”„
9. **Embed HTML**: Enhance apps with `st.markdown()` using HTML inside markdown. ๐ŸŒ
10. **Deploy easily**: Use `streamlit.io` for one-click deployment. ๐Ÿš€
""",
"typescript": """
### TypeScript - Top 10 Code Tips ๐Ÿ’ป
1. **Use type annotations**: Always annotate variables and function return types. ๐Ÿ“
2. **Prefer interfaces over types**: Interfaces can be extended more easily than types. ๐Ÿ’ช
3. **Use union and intersection types**: Combine types in flexible ways with `|` and `&`. ๐Ÿ› ๏ธ
4. **Utilize generics**: Write reusable functions and components with generics. ๐Ÿ”„
5. **Avoid `any`**: Avoid using `any` type unless absolutely necessary. ๐Ÿšซ
6. **Leverage optional chaining**: Safely access deeply nested properties. โ“
7. **Use `readonly` for immutability**: Enforce immutability with `readonly`. ๐Ÿ”’
8. **Utilize `never` type**: Use `never` for unreachable code paths and exhaustive checks. ๐Ÿšง
9. **Understand narrowing**: Use control flow analysis to narrow down types. ๐Ÿงฎ
10. **Enable strict mode**: Always turn on strict mode for better type safety. ๐Ÿ›ก๏ธ
""",
"react_native": """
### React Native - Top 10 Code Tips ๐Ÿ“ฑ
1. **Use `StyleSheet`**: Organize and optimize styles with `StyleSheet.create`. ๐ŸŽจ
2. **Avoid inline styles**: Use stylesheets for reusability and performance. ๐Ÿ–Œ๏ธ
3. **Leverage Flexbox**: Design responsive layouts with Flexbox. ๐Ÿ“
4. **Handle platform-specific code**: Use `Platform` module for OS-specific logic. ๐Ÿ› ๏ธ
5. **Optimize images**: Use `Image` and `ImageBackground` components efficiently. ๐Ÿ–ผ๏ธ
6. **Utilize hooks**: Use hooks like `useEffect` and `useState` for state management. ๐ŸŒ€
7. **Use third-party libraries**: Incorporate libraries like `react-navigation` and `redux`. ๐Ÿ“š
8. **Optimize for performance**: Avoid unnecessary re-renders using `React.memo` and `useCallback`. ๐ŸŽ๏ธ
9. **Handle gestures properly**: Use `react-native-gesture-handler` for gesture-based navigation. ๐Ÿ“ฒ
10. **Utilize TypeScript**: Combine React Native with TypeScript for safer code. ๐Ÿ’ป
""",
"libraries": """
### Top 10 Python Libraries for SVG, TypeScript, and React Components ๐Ÿ› ๏ธ
1. **lxml**: Efficiently parse and manipulate XML, including SVG. ๐Ÿ“„
2. **svgwrite**: Easily create and modify SVG files in Python. ๐Ÿ–ผ๏ธ
3. **CairosVG**: Convert SVG files to various formats like PNG. ๐Ÿ”„
4. **pydantic**: Handle data validation and complex typing in TypeScript code generation. โœ…
5. **datamodel-code-generator**: Automatically generate TypeScript code from Python data models. ๐Ÿ’ป
6. **PyV8**: Run JavaScript code from within Python, useful for generating dynamic assets. ๐Ÿง‘โ€๐Ÿ’ป
7. **transcrypt**: Compile Python code to JavaScript for use with TypeScript projects. ๐Ÿ”„
8. **reactpy**: Build interactive UIs using Python for web and mobile (React-like). ๐Ÿ“ฒ
9. **react-native-svg**: Handle SVG assets in React Native applications. ๐Ÿ“
10. **streamlit-component-template**: Create custom React components inside Streamlit apps. ๐ŸŽ›๏ธ
"""
}
# Set up the sidebar
st.sidebar.title("Insights on Technologies ๐Ÿ› ๏ธ")
sections = ["Python Tips", "Streamlit Tips", "TypeScript Tips", "React Native Tips", "Python Libraries"]
selected_section = st.sidebar.selectbox("Choose a Section:", sections)
# Main content display
if selected_section == "Python Tips":
st.markdown(markdown_data["python"])
elif selected_section == "Streamlit Tips":
st.markdown(markdown_data["streamlit"])
elif selected_section == "TypeScript Tips":
st.markdown(markdown_data["typescript"])
elif selected_section == "React Native Tips":
st.markdown(markdown_data["react_native"])
elif selected_section == "Python Libraries":
st.markdown(markdown_data["libraries"])
# Tabs for interactive code examples
st.subheader("Interactive Code Examples ๐Ÿ’ป")
tabs = st.tabs(["Python", "Streamlit", "TypeScript", "React Native"])
# Example Python code generation
with tabs[0]:
st.markdown("""
**Example: Python Generating TypeScript** ๐ŸŽจ
```python
def generate_typescript_button():
return '''
import React from 'react';
import { Button } from 'react-native';
interface ButtonProps {
title: string;
onPress: () => void;
}
const CustomButton: React.FC<ButtonProps> = ({ title, onPress }) => (
<Button title={title} onPress={onPress} />
);
export default CustomButton;
'''
```
""")
st.button("Generate TypeScript Code ๐Ÿ–‹๏ธ")
# Streamlit Example
with tabs[1]:
st.markdown("""
**Example: Custom Streamlit Widget** ๐ŸŽ›๏ธ
```python
import streamlit as st
def custom_button(label):
st.write(f"Button: {label}")
if st.button(label):
st.write(f"Button {label} was clicked!")
custom_button("Click Me")
```
""")
st.button("Generate Streamlit Code ๐Ÿ’ป")
# TypeScript Example
with tabs[2]:
st.markdown("""
**Example: TypeScript Component in React Native** ๐Ÿ“ฑ
```typescript
import React from 'react';
import { View, Text, StyleSheet } from 'react-native';
const HelloWorld = () => (
<View style={styles.container}>
<Text style={styles.text}>Hello, World!</Text>
</View>
);
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
text: {
fontSize: 24,
color: 'blue',
},
});
export default HelloWorld;
```
""")
st.button("Generate React Native Code ๐Ÿ“ฒ")
# React Native Example
with tabs[3]:
st.markdown("""
**Example: React Native with TypeScript** ๐Ÿ’ป
```typescript
import React from 'react';
import { Text, View, Button } from 'react-native';
interface AppProps {
title: string;
}
const App: React.FC<AppProps> = ({ title }) => (
<View>
<Text>{title}</Text>
<Button title="Click Me" onPress={() => alert('Button Pressed!')} />
</View>
);
export default App;
```
""")
st.button("Generate Full React Native App ๐Ÿ“ฒ")
# Footer
st.sidebar.info("๐ŸŽ‰ Enjoy exploring Python, Streamlit, TypeScript, and React Native!")