chandralegend commited on
Commit
47c3daf
β€’
1 Parent(s): 8210d08

added tutorial content

Browse files
.sessions/johndoe/images/2d4f8d74-18e0-4a26-bd63-d1a62ee3aca0_Angry_.jpg ADDED
.sessions/johndoe/images/83075496-fa6b-4266-8237-6d51c450f143_Happy_.jpg ADDED
.sessions/johndoe/images/try.jpg ADDED
.sessions/johndoe/level.txt CHANGED
@@ -1 +1 @@
1
- 3
 
1
+ 5
0_Introduction.py CHANGED
@@ -5,20 +5,28 @@ from utils.login import initialize_login
5
  initialize_login()
6
  initialize_level()
7
 
8
- LEVEL=0
 
9
 
10
  def intro_page():
11
- st.header("AI Eye Tutorial Template")
12
- st.subheader("Level 0: Introduction")
 
 
 
 
 
 
13
 
14
- st.write("""Welcome to the AI Eye Tutorial Template! This template is designed to help you create your own AI Eye tutorial.
15
- The template is divided into levels, and each level has a set of tasks that you need to complete before you can move on to the next level.
16
- You can use this template to create your own tutorial by completing the tasks in each level and adding your own content. You can also use
17
- this template to learn how to use AI Eye by completing the tasks in each level.""")
18
 
19
- st.info(f"Current Level: {get_level()}")
20
 
21
- if st.button("Complete"):
22
  complete_level(LEVEL)
23
 
24
- render_page(intro_page, LEVEL)
 
 
5
  initialize_login()
6
  initialize_level()
7
 
8
+ LEVEL = 0
9
+
10
 
11
  def intro_page():
12
+ st.header("Facial Emotion Recognition")
13
+ st.subheader("Introduction")
14
+
15
+ st.write(
16
+ """Welcome to the interactive tutorial on creating your very own Emotion Detection Application! In this tutorial, you will learn how to build
17
+ a simple application that can recognize and detect emotions from facial expressions. Emotion detection is a fascinating field that combines computer vision
18
+ and machine learning techniques. Are you ready to dive into the exciting world of emotion detection?"""
19
+ )
20
 
21
+ st.image(
22
+ "https://miro.medium.com/v2/resize:fit:720/0*Ko6oX3rRb0aTgdUI.gif",
23
+ use_column_width=True,
24
+ )
25
 
26
+ st.info(f"Click on the button below to start the tutorial!")
27
 
28
+ if st.button("I am Ready!"):
29
  complete_level(LEVEL)
30
 
31
+
32
+ render_page(intro_page, LEVEL)
README.md CHANGED
@@ -1,8 +1,8 @@
1
  ---
2
- title: Aieye Tutorial Template
3
- emoji: 🌍
4
- colorFrom: green
5
- colorTo: purple
6
  sdk: streamlit
7
  sdk_version: 1.21.0
8
  app_file: 0_Introduction.py
 
1
  ---
2
+ title: Emotion Detection
3
+ emoji: πŸ§‘πŸ»β€πŸ€β€πŸ§‘πŸΎ
4
+ colorFrom: yellow
5
+ colorTo: orange
6
  sdk: streamlit
7
  sdk_version: 1.21.0
8
  app_file: 0_Introduction.py
pages/1_Step_1.py DELETED
@@ -1,15 +0,0 @@
1
- import streamlit as st
2
- from utils.levels import complete_level, render_page, initialize_level
3
- LEVEL = 1
4
-
5
- initialize_level()
6
-
7
- def step1_page():
8
- st.header("Step 1")
9
- st.subheader("Level 1: Introduction")
10
- st.write("This is the first step of the tutorial. You can add your own content here.")
11
-
12
- if st.button("Complete"):
13
- complete_level(LEVEL)
14
-
15
- render_page(step1_page, LEVEL)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pages/1_Technology Behind It.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from utils.levels import complete_level, render_page, initialize_level
3
+ from utils.login import initialize_login
4
+
5
+ LEVEL = 1
6
+
7
+ initialize_login()
8
+ initialize_level()
9
+
10
+
11
+
12
+ def step1_page():
13
+ st.header("Technology Behind It")
14
+ st.markdown(
15
+ """
16
+ ### How does it work?
17
+ Our emotion detection application works like a special brain that understands facial expressions and guesses
18
+ how someone is feeling. Here's how it works:
19
+
20
+ 1. **Looking for Faces**: First, the application looks at a picture of a person's face. It tries to find the
21
+ important parts, like the eyes, nose, and mouth. It's like when we look at a picture and focus on someone's face.
22
+
23
+ 2. **Noticing Features**: Next, the application pays attention to the different parts of the face. It looks for things
24
+ like the shape of the mouth, the wrinkles around the eyes, and how the eyebrows are positioned. Just like we notice
25
+ if someone is smiling or frowning by looking at their mouth and eyes.
26
+ """
27
+ )
28
+ st.image(
29
+ "https://media.istockphoto.com/id/1136827583/photo/futuristic-and-technological-scanning-of-face-for-facial-recognition.jpg?s=612x612&w=0&k=20&c=GsqBYxvE64TS8HY__OSn6qZU5HPBhIemnqjyf37TkQo=",
30
+ use_column_width=True,
31
+ )
32
+ st.markdown(
33
+ """
34
+ 3. **Understanding Expressions**: Based on these features, the application tries to guess how the person is feeling. It
35
+ knows that a big smile usually means happiness, while a furrowed brow might mean someone is angry or worried. It
36
+ uses all the features it noticed to make its best guess.
37
+ """
38
+ )
39
+ st.image(
40
+ "https://miro.medium.com/v2/resize:fit:1200/1*4rjT-RSOTdlPqp1UwcF3tg.jpeg",
41
+ use_column_width=True,
42
+ )
43
+ st.markdown(
44
+ """
45
+ 4. **Practicing and Learning**: Our application gets better at understanding emotions by looking at lots of pictures of
46
+ faces with different expressions. It learns from these pictures and becomes smarter over time, just like we get
47
+ better at recognizing emotions by seeing and experiencing them ourselves.
48
+
49
+ So, our emotion detection model is like a clever brain that looks at faces, notices important features, and guesses
50
+ how someone is feeling based on those features. It's a way for computers to understand emotions, just like we do as
51
+ humans!
52
+ """
53
+ )
54
+
55
+ st.info("Click on the button below to continue!")
56
+
57
+ if st.button("Complete"):
58
+ complete_level(LEVEL)
59
+
60
+
61
+ render_page(step1_page, LEVEL)
pages/2_Collecting Your Data.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from utils.levels import complete_level, render_page, initialize_level
3
+ from utils.login import get_login
4
+ import os
5
+ import uuid
6
+ from utils.login import initialize_login
7
+
8
+ initialize_login()
9
+ initialize_level()
10
+
11
+ LEVEL = 2
12
+
13
+
14
+ def step2_page():
15
+ st.header("Collecting Your Data")
16
+ st.write(
17
+ "Now it's time to collect the pictures we need to teach our application about emotions. But remember, we should always ask for permission before taking someone's picture. We can use a smartphone or a digital camera to capture different facial expressions. It's important to take pictures of different people and show different emotions like happiness, sadness, surprise, and more. This will help our application understand emotions better!"
18
+ )
19
+
20
+ img_dir = os.path.join(".sessions", get_login()["username"], "images")
21
+ os.makedirs(img_dir, exist_ok=True)
22
+
23
+ emotion = st.selectbox(
24
+ "Select an emotion",
25
+ ("Happy", "Sad", "Surprised", "Angry", "Disgusted", "Neutral", "Fearful"),
26
+ )
27
+ picture = st.camera_input("Take a picture")
28
+ if picture:
29
+ if st.button("Save"):
30
+ img_name = str(uuid.uuid4()) + f"_{emotion}_" + ".jpg"
31
+ img_path = os.path.join(img_dir, img_name)
32
+ with open(img_path, "wb") as f:
33
+ f.write(picture.getvalue())
34
+ st.success("Image added successfully!")
35
+
36
+ images = os.listdir(img_dir)
37
+ if len(images) > 0:
38
+ st.subheader("Your Images")
39
+ cols = st.columns(4)
40
+ for i, img in enumerate(images):
41
+ img_emotion = img.split("_")[1]
42
+ cols[i % 4].image(os.path.join(img_dir, img), use_column_width=True)
43
+ cols[i % 4].write(img_emotion)
44
+
45
+ if st.button("Clear All"):
46
+ for img in images:
47
+ os.remove(os.path.join(img_dir, img))
48
+ st.success("All images cleared!")
49
+ st.experimental_rerun()
50
+
51
+ st.info("If you are satisfied with your images, click on the button below to complete this level.")
52
+ if st.button("Complete"):
53
+ complete_level(LEVEL)
54
+
55
+
56
+ render_page(step2_page, LEVEL)
pages/2_Step_2.py DELETED
@@ -1,16 +0,0 @@
1
- import streamlit as st
2
- from utils.levels import complete_level, render_page, initialize_level
3
-
4
- initialize_level()
5
-
6
- LEVEL = 2
7
-
8
- def step2_page():
9
- st.header("Step 2")
10
- st.subheader("Level 2: Introduction")
11
- st.write("This is the second step of the tutorial. You can add your own content here.")
12
-
13
- if st.button("Complete"):
14
- complete_level(LEVEL)
15
-
16
- render_page(step2_page, LEVEL)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pages/3_Training the Model.py ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from utils.levels import complete_level, render_page, initialize_level
3
+ from utils.login import get_login, initialize_login
4
+ from utils.inference import query
5
+ import os
6
+ import time
7
+
8
+ initialize_login()
9
+ initialize_level()
10
+
11
+ LEVEL = 3
12
+
13
+
14
+ def infer(image):
15
+ time.sleep(1)
16
+ output = query(image)
17
+ cols = st.columns(2)
18
+ cols[0].image(image, use_column_width=True)
19
+ with cols[1]:
20
+ for item in output:
21
+ st.progress(item["score"], text=item["label"])
22
+
23
+
24
+ def step3_page():
25
+ st.header("Training the Model")
26
+ st.markdown(
27
+ """
28
+ ### How It Learns About Emotions?
29
+ Now that we have our pictures of different facial expressions, it's time to teach our emotion detection application how to understand emotions. Here's how the training process works:
30
+
31
+ 1. **Getting Ready**: Imagine we have a special teacher who will help our application learn about emotions. We gather all the pictures we took and organize them neatly for the teacher to use.
32
+
33
+ 2. **Showing Examples**: We show our teacher the pictures one by one and tell them what emotion each picture represents. We might say, "This picture shows happiness," or "This picture shows sadness." Our teacher pays close attention to these examples.
34
+ """
35
+ )
36
+ st.image(
37
+ "https://1.bp.blogspot.com/-Cehw4NbX2L8/X1-DJeQgtmI/AAAAAAAAKeE/fA55q9EXsgQLU0trbgX_vJkiFMwR927yQCLcBGAsYHQ/s853/final.gif",
38
+ use_column_width=True,
39
+ )
40
+ st.markdown(
41
+ """
42
+ 3. **Finding Patterns**: Our teacher starts to notice patterns in the pictures and the emotions we assigned to them. They might see that smiling faces usually mean happiness, or that certain features are common in sad expressions. These patterns help the teacher understand how emotions are expressed on people's faces.
43
+ """
44
+ )
45
+ st.image(
46
+ "https://miro.medium.com/v2/resize:fit:1358/1*KoHwRNZGrVrhdbye3BDEew.png",
47
+ use_column_width=True,
48
+ )
49
+ st.markdown(
50
+ """
51
+ 4. **Learning and Remembering**: The more pictures our teacher sees, the better they become at understanding emotions. They remember the patterns they found and use that knowledge to guess emotions in new pictures. It's like how we get better at recognizing emotions by seeing lots of different faces and expressions.
52
+ 5. **Checking Understanding**: To make sure our teacher is doing a good job, we give them more pictures and ask them to guess the emotions. If they make a mistake, we help them understand where they went wrong and show them the correct answer. This helps our teacher learn and improve their understanding of emotions.
53
+
54
+ By repeating this process many times, our emotion detection application gradually becomes better at recognizing emotions in pictures. It learns from the examples we showed it and gets smarter over time. It's like training a special friend to understand how we feel based on our facial expressions!
55
+ """
56
+ )
57
+
58
+ st.info(
59
+ "Now it's your turn to train the model! Click on the button below to train the model with your data!"
60
+ )
61
+
62
+ if st.button("Train Model"):
63
+ my_bar = st.progress(0, text="Training...")
64
+ img_dir = os.path.join(".sessions", get_login()["username"], "images")
65
+ images = os.listdir(img_dir)
66
+ if len(images) > 0:
67
+ for i, image in enumerate(images):
68
+ infer(os.path.join(img_dir, image))
69
+ my_bar.progress(int((i + 1) / len(images) * 100), text="Training...")
70
+ my_bar.progress(100, text="Successfully Trained!")
71
+ st.success("Model trained successfully!")
72
+ complete_level(LEVEL)
73
+ else:
74
+ my_bar.empty()
75
+ st.error("You have not taken any images yet! Do the previous steps first!")
76
+
77
+
78
+ render_page(step3_page, LEVEL)
pages/4_Trying It Out.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from utils.levels import complete_level, render_page, initialize_level
3
+ from utils.login import get_login, initialize_login
4
+ from utils.inference import query
5
+ import os
6
+ import time
7
+
8
+ initialize_login()
9
+ initialize_level()
10
+
11
+ LEVEL = 4
12
+
13
+
14
+ def infer(image):
15
+ time.sleep(1)
16
+ output = query(image)
17
+ cols = st.columns(2)
18
+ cols[0].image(image, use_column_width=True)
19
+ with cols[1]:
20
+ for item in output:
21
+ st.progress(item["score"], text=item["label"])
22
+
23
+
24
+ def step4_page():
25
+ st.header("Trying It Out")
26
+ st.markdown(
27
+ """
28
+ ### How Our Emotion Detection Application Works
29
+ Now that we have trained our emotion detection application, let's see how it works in action! Here's a simple explanation of how the application recognizes emotions:
30
+
31
+ 1. **Looking at Faces**: When we use our emotion detection application, we can show it a picture of a face or use a camera to capture a real-time image. It's like giving our application a chance to see someone's expression.
32
+
33
+ 2. **Observing the Features**: The application carefully looks at the face and pays attention to different parts, like the eyes, mouth, and eyebrows. It tries to understand the expressions by noticing how these parts look and how they are positioned. It's like the application is taking a close look at the face, just like we do when we try to understand someone's emotions.
34
+ """
35
+ )
36
+ st.image(
37
+ "https://camo.githubusercontent.com/3bb4e2eba7c8a91d71916496bc775e870222f19bb5098cb4bc514ed60078c1e7/68747470733a2f2f626c6f672e7161746573746c61622e636f6d2f77702d636f6e74656e742f75706c6f6164732f323032302f30312f4d4c5f6578616d706c652e6769663f7261773d74727565",
38
+ use_column_width=True,
39
+ )
40
+ st.markdown(
41
+ """
42
+ 3. **Guessing the Emotion**: Based on what it observed, our application uses the knowledge it learned during training to make its best guess about the person's emotion. It remembers the patterns it saw before and tries to match them with the features it observed. It might think the person looks happy, sad, or maybe surprised!
43
+ """
44
+ )
45
+ st.image(
46
+ "https://miro.medium.com/v2/resize:fit:1358/1*KoHwRNZGrVrhdbye3BDEew.png",
47
+ use_column_width=True,
48
+ )
49
+ st.markdown(
50
+ """
51
+ 4. **Providing a Result**: Finally, our emotion detection application tells us what emotion it thinks the person is feeling. It might say, "I think this person looks happy!" or "I think this person looks sad." It's like having a virtual friend who can give us their guess about someone's emotion.
52
+
53
+ By going through these steps, our emotion detection application can quickly analyze faces and give us an idea of how someone might be feeling. It's like having a special friend who can understand and guess emotions based on facial expressions!
54
+ """
55
+ )
56
+
57
+ st.info(
58
+ "Now that we know how our emotion detection application works, let's try it out!"
59
+ )
60
+
61
+ st.info("Select an image to analyze!")
62
+ input_type = st.radio("Select the Input Type", ["Image", "Camera"])
63
+
64
+ if input_type == "Camera":
65
+ image = st.camera_input("Take a picture")
66
+ byte_image = image.getvalue() if image else None
67
+ else:
68
+ image = st.file_uploader("Upload an image", type=["png", "jpg", "jpeg"])
69
+ byte_image = image.read() if image else None
70
+ try_img = os.path.join(".sessions", get_login()["username"], "images", "try.jpg")
71
+ if byte_image:
72
+ with open(try_img, "wb") as f:
73
+ f.write(byte_image)
74
+ infer(try_img)
75
+
76
+ st.info("Click on the button below to complete this level!")
77
+ if st.button("Complete Level"):
78
+ complete_level(LEVEL)
79
+
80
+
81
+ render_page(step4_page, LEVEL)
pages/{3_Congratulations.py β†’ 5_Congratulations.py} RENAMED
@@ -1,13 +1,12 @@
1
  import streamlit as st
2
- from utils.levels import complete_level, render_page, initialize_level
3
 
4
  initialize_level()
5
 
6
- LEVEL = 3
7
 
8
- def step1_page():
9
  st.header("Congratulations!")
10
  st.subheader("You have completed the tutorial!")
11
- st.write("You can now use this template to create your own tutorial.")
12
 
13
- render_page(step1_page, LEVEL)
 
1
  import streamlit as st
2
+ from utils.levels import render_page, initialize_level
3
 
4
  initialize_level()
5
 
6
+ LEVEL = 5
7
 
8
+ def complete_page():
9
  st.header("Congratulations!")
10
  st.subheader("You have completed the tutorial!")
 
11
 
12
+ render_page(complete_page, LEVEL)
utils/__pycache__/__init__.cpython-310.pyc CHANGED
Binary files a/utils/__pycache__/__init__.cpython-310.pyc and b/utils/__pycache__/__init__.cpython-310.pyc differ
 
utils/__pycache__/inference.cpython-310.pyc ADDED
Binary file (617 Bytes). View file
 
utils/__pycache__/levels.cpython-310.pyc CHANGED
Binary files a/utils/__pycache__/levels.cpython-310.pyc and b/utils/__pycache__/levels.cpython-310.pyc differ
 
utils/__pycache__/login.cpython-310.pyc CHANGED
Binary files a/utils/__pycache__/login.cpython-310.pyc and b/utils/__pycache__/login.cpython-310.pyc differ
 
utils/inference.py ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+
3
+ API_URL = "https://api-inference.huggingface.co/models/CynthiaCR/emotions_classifier"
4
+ headers = {"Authorization": "Bearer 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"}
5
+
6
+ def query(filename):
7
+ with open(filename, "rb") as f:
8
+ data = f.read()
9
+ response = requests.post(API_URL, headers=headers, data=data)
10
+ return response.json()