Update app.py
Browse files
app.py
CHANGED
@@ -5,8 +5,8 @@ from PIL import Image
|
|
5 |
import numpy as np
|
6 |
from deepface import DeepFace # Replacing FER with DeepFace
|
7 |
from dotenv import load_dotenv
|
8 |
-
import time # For rate limiting
|
9 |
|
|
|
10 |
print("DeepFace is installed and ready to use!")
|
11 |
print("Google Generative AI module is successfully imported!")
|
12 |
|
@@ -46,10 +46,10 @@ def detect_emotions(image):
|
|
46 |
def analyze_emotions_with_llm(emotion, emotions):
|
47 |
emotion_analysis = f"{emotion}: {emotions[emotion]:.2f}"
|
48 |
analysis_prompt = f"""
|
49 |
-
As a mental health and emotional well-being expert, analyze the following detected emotions.
|
50 |
-
Detected Emotions:
|
51 |
{emotion_analysis}
|
52 |
-
|
53 |
1. Identify any potential signs of depression based on the detected emotions.
|
54 |
2. Explain the reasoning behind your identification.
|
55 |
3. Provide recommendations for addressing any identified issues.
|
@@ -79,20 +79,20 @@ def display_response_content(response):
|
|
79 |
st.title("AI-Powered Depression and Emotion Detection System")
|
80 |
st.text("Use the AI system for detecting depression and emotions from images.")
|
81 |
|
82 |
-
# Tabs for different functionalities
|
83 |
-
|
84 |
-
|
85 |
-
with tab1:
|
86 |
st.header("Image Analysis")
|
87 |
uploaded_file = st.file_uploader("Upload an image for analysis", type=["jpg", "jpeg", "png"], help="Please upload an image file.")
|
88 |
submit_image = st.button('Analyze Image')
|
89 |
|
90 |
if submit_image:
|
91 |
if uploaded_file is not None:
|
92 |
-
image = Image.open(uploaded_file)
|
93 |
-
emotion, emotions = detect_emotions(image)
|
94 |
-
if emotion:
|
95 |
-
response = analyze_emotions_with_llm(emotion, emotions)
|
96 |
-
display_response_content(response)
|
97 |
else:
|
98 |
-
st.write("No emotions detected in the image.")
|
|
|
|
|
|
5 |
import numpy as np
|
6 |
from deepface import DeepFace # Replacing FER with DeepFace
|
7 |
from dotenv import load_dotenv
|
|
|
8 |
|
9 |
+
# Print out successful imports
|
10 |
print("DeepFace is installed and ready to use!")
|
11 |
print("Google Generative AI module is successfully imported!")
|
12 |
|
|
|
46 |
def analyze_emotions_with_llm(emotion, emotions):
|
47 |
emotion_analysis = f"{emotion}: {emotions[emotion]:.2f}"
|
48 |
analysis_prompt = f"""
|
49 |
+
### As a mental health and emotional well-being expert, analyze the following detected emotions.
|
50 |
+
### Detected Emotions:
|
51 |
{emotion_analysis}
|
52 |
+
### Analysis Output:
|
53 |
1. Identify any potential signs of depression based on the detected emotions.
|
54 |
2. Explain the reasoning behind your identification.
|
55 |
3. Provide recommendations for addressing any identified issues.
|
|
|
79 |
st.title("AI-Powered Depression and Emotion Detection System")
|
80 |
st.text("Use the AI system for detecting depression and emotions from images.")
|
81 |
|
82 |
+
# Tabs for different functionalities (only image analysis in this version)
|
83 |
+
with st.container():
|
|
|
|
|
84 |
st.header("Image Analysis")
|
85 |
uploaded_file = st.file_uploader("Upload an image for analysis", type=["jpg", "jpeg", "png"], help="Please upload an image file.")
|
86 |
submit_image = st.button('Analyze Image')
|
87 |
|
88 |
if submit_image:
|
89 |
if uploaded_file is not None:
|
90 |
+
image = Image.open(uploaded_file) # Open the uploaded image
|
91 |
+
emotion, emotions = detect_emotions(image) # Detect emotions using DeepFace
|
92 |
+
if emotion: # If emotions are detected
|
93 |
+
response = analyze_emotions_with_llm(emotion, emotions) # Analyze detected emotions with LLM
|
94 |
+
display_response_content(response) # Display the analysis response
|
95 |
else:
|
96 |
+
st.write("No emotions detected in the image.") # If no emotion is detected
|
97 |
+
else:
|
98 |
+
st.write("Please upload an image first.") # Prompt for image upload if none is uploaded
|