hari3485 commited on
Commit
c214a99
Β·
verified Β·
1 Parent(s): cced416

Update pages/Data Collection.py

Browse files
Files changed (1) hide show
  1. pages/Data Collection.py +92 -52
pages/Data Collection.py CHANGED
@@ -1,71 +1,111 @@
1
  import streamlit as st
2
 
3
- # App title
4
- st.title("Working with HTML Data using Python")
5
 
6
- # HTML and DataFrames Section
7
- st.header("HTML and DataFrames")
 
8
 
9
- st.write("""
10
- - **HTML (HyperText Markup Language)** is a semi-structured data format.
11
- - HTML uses tags like `<table>`, `<tr>`, `<th>`, and `<td>` to structure tabular data.
12
- - Unlike XML, HTML does not allow creating custom tags freely.
13
- - Not all HTML content can be converted into dataframes, especially paragraph text or unstructured data.
14
- - Typically, only table-related elements (`<table>`, `<tr>`, `<th>`, `<td>`) can be converted into dataframes.
15
- """)
16
 
17
- # Reading HTML Files Section
18
- st.header("Reading HTML Files into DataFrames")
 
 
19
 
20
- st.write("**Reading HTML Files:**")
21
- st.code("""
22
- import pandas as pd
23
- tables = pd.read_html(path_or_buffer)
24
- """, language="python")
25
 
26
- st.write("""
27
- - **`pd.read_html(path_or_buffer)`** reads HTML files or websites containing tables.
28
- - Extracts all tables and returns them as a list of dataframes.
29
- """)
30
 
31
- st.write("**Accessing Specific Tables:**")
32
- st.code("""
33
- # Accessing the first table from the list
34
- table = tables[0]
35
- """, language="python")
36
 
37
- st.write("""
38
- - Each table is stored in the list by index.
39
- - Use indexing to select the table you want to work with.
40
- """)
 
 
 
 
 
 
 
 
 
 
41
 
42
- st.write("**Limitations:**")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  st.write("""
44
- - Not all websites or HTML files can be read, even if they have tables.
45
- - Issues like authorization restrictions can prevent reading certain tables.
 
 
 
46
  """)
47
 
48
- st.write("**Using the `match` Parameter:**")
49
- st.code("""
50
- # Reading a specific table using the match parameter
51
- tables = pd.read_html(path, match="keyword")
52
- """, language="python")
 
 
 
53
 
 
 
 
54
  st.write("""
55
- - To locate specific tables, use `match="keyword"` while reading HTML.
56
- - The `match` parameter searches for tables containing the specified keyword.
57
  """)
58
 
59
- # Exporting DataFrames Section
60
- st.header("Exporting DataFrames to HTML")
61
 
62
- st.write("**Exporting DataFrame to HTML:**")
63
- st.code("""
64
- # Exporting a dataframe to an HTML file
65
- df.to_html("output.html")
66
- """, language="python")
67
 
68
- st.write("""
69
- - Converts a dataframe into an HTML file.
70
- - Saves the dataframe in an HTML-compatible table format at the specified path.
71
- """)
 
1
  import streamlit as st
2
 
3
+ # Title
4
+ st.title("πŸ“Έ Understanding Images and How to Handle Them")
5
 
6
+ # Helper function to style text with HTML
7
+ def colored_subheader(text, color):
8
+ st.markdown(f"<h3 style='color:{color};'>{text}</h3>", unsafe_allow_html=True)
9
 
10
+ # What is an Image?
11
+ st.header("What is an Image? πŸ–ΌοΈ")
12
+ st.write("An image is a **2D representation of the visible light spectrum**. It is created when light reflects off objects and is captured by a device like a camera or our eyes.")
 
 
 
 
13
 
14
+ # How is an Image Formed?
15
+ st.header("How is an Image Formed? πŸŒžπŸ“Έ")
16
+ colored_subheader("1. Source of Light 🌟", "blue")
17
+ st.write("- Light comes from sources like the **sun**, **moon**, or **stars**.")
18
 
19
+ colored_subheader("2. Reflection πŸ”„", "green")
20
+ st.write("- Light hits an object and **bounces back** (this is called reflection).")
 
 
 
21
 
22
+ colored_subheader("3. Capture πŸ“Έ", "orange")
23
+ st.write("- The reflected light is captured by a camera or eyes, forming an image.")
 
 
24
 
25
+ colored_subheader("4. Visible Light Only 🌈", "purple")
26
+ st.write("- Not all light can create images (e.g., gamma rays or X-rays are invisible).")
27
+ st.write("- **Visible light** is required to see and capture images.")
 
 
28
 
29
+ # Images and Pixels
30
+ st.header("Images and Pixels 🟦⬜")
31
+ colored_subheader("What are Pixels? πŸ“", "red")
32
+ st.write("- Pixels are tiny squares that make up an image.")
33
+ st.write("- Each pixel contains information about color and brightness.")
34
+
35
+ colored_subheader("Resolution πŸ“", "darkblue")
36
+ st.write("- The number of pixels in an image determines its resolution.")
37
+ st.write("- **More pixels = Clearer image = More details.**")
38
+
39
+ # Why are Images Like a Grid?
40
+ st.header("Why are Images Like a Grid? πŸ”³")
41
+ colored_subheader("Grid Structure 🧩", "darkgreen")
42
+ st.write("- Images are stored as grids because they are made of pixels, each representing a feature like color or brightness.")
43
 
44
+ colored_subheader("Difference from Tabular Data πŸ“Š", "teal")
45
+ st.write("- Tabular data has rows as data points and columns as features.")
46
+ st.write("- In images, the entire grid represents a **single data point**, with each pixel as a feature.")
47
+
48
+ # How Are Images Represented in Python?
49
+ st.header("How Are Images Represented in Python? 🐍")
50
+ colored_subheader("Using NumPy Arrays πŸ“Š", "maroon")
51
+ st.write("- Images are converted into arrays of numbers for computers to process.")
52
+ st.write("- Example: A black-and-white image is represented as a 2D array.")
53
+
54
+ # Color Spaces in Images
55
+ st.header("Color Spaces in Images 🌈")
56
+
57
+ # Black and White
58
+ colored_subheader("1. Black and White 🏴", "black")
59
+ st.write("- Represents two colors: **Black (0)** and **White (255)**.")
60
+ st.write("- **Demerit**: Cannot preserve other colors like red, blue, or green.")
61
+
62
+ # Grayscale
63
+ colored_subheader("2. Grayscale πŸ–€", "gray")
64
+ st.write("- Preserves **256 shades of gray** (from 0 to 255).")
65
+ st.write("- **Demerit**: Cannot handle colored images (like red, green, blue).")
66
+
67
+ # RGB
68
+ colored_subheader("3. RGB (Red, Green, Blue) 🌈", "blue")
69
+ st.write("- Most common color space.")
70
+ st.write("- Colors are created by mixing **Red**, **Green**, and **Blue** intensities.")
71
+ st.write("- Each channel has values ranging from **0 to 255**.")
72
+ st.write("- **Advantages**: Can represent up to **16 million colors**.")
73
+
74
+ # How Images are Converted to Arrays
75
+ st.header("How Images are Converted to Arrays πŸ–©")
76
+ colored_subheader("Steps to Convert Images πŸ› οΈ", "brown")
77
  st.write("""
78
+ 1. **Step 1: Convert the Image to Numbers**: Each pixel’s color and brightness are stored as numbers.
79
+ 2. **Step 2: Create Arrays**:
80
+ - A black-and-white image becomes a **2D array** (rows and columns).
81
+ - A colored image (RGB) becomes a **3D array** with separate layers for red, green, and blue.
82
+ 3. **Step 3: Process the Array**: The computer processes these arrays to analyze or modify the image.
83
  """)
84
 
85
+ # Differences Between 2D and 3D Arrays in Images
86
+ st.header("Differences Between 2D and 3D Arrays in Images πŸ“")
87
+ colored_subheader("Comparison πŸ†š", "indigo")
88
+ st.table({
89
+ "Type": ["2D Array (Grayscale)", "3D Array (RGB)"],
90
+ "Explanation": ["Used for grayscale images (shades of gray).", "Used for RGB images (multiple channels)."],
91
+ "Values": ["0–255", "(R, G, B) values, each 0–255"]
92
+ })
93
 
94
+ # Notes
95
+ st.header("Notes πŸ“")
96
+ colored_subheader("Key Points ✏️", "gold")
97
  st.write("""
98
+ - **Color Spaces**: Essential to represent and preserve the colors in an image.
99
+ - **Numpy Library**: Widely used in Python for processing images as arrays.
100
  """)
101
 
102
+ # Buttons
103
+ col1, col2 = st.columns(2)
104
 
105
+ with col1:
106
+ if st.button("πŸ”„ Basic Operations Using OpenCV"):
107
+ st.write("Redirecting to the next section: Basic Operations Using OpenCV...")
 
 
108
 
109
+ with col2:
110
+ if st.button("πŸ”™ Back"):
111
+ st.write("Going back to the previous section...")