Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrated features for depression detection #264

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
Binary file added DepressionDetection/.DS_Store
Binary file not shown.
74 changes: 74 additions & 0 deletions DepressionDetection/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import os
import cv2
import dlib
import numpy as np
from flask import Flask, render_template, request, redirect, url_for
from fer import FER

app = Flask(__name__)

UPLOAD_FOLDER = 'data'
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER

if not os.path.exists(UPLOAD_FOLDER):
os.makedirs(UPLOAD_FOLDER)

# Initialize Dlib's face detector
detector = dlib.get_frontal_face_detector()
# Initialize the FER emotion detector
emotion_detector = FER()

@app.route('/')
def index():
return render_template('index.html')

@app.route('/submit', methods=['POST'])
def submit():
if 'image_file' not in request.files:
return "No file part in the request"

file = request.files['image_file']
if file.filename == '':
return "No file selected"

if file:
# Save the uploaded file
filepath = os.path.join(app.config['UPLOAD_FOLDER'], file.filename)
file.save(filepath)

# Read the image and convert to grayscale for face detection
image = cv2.imread(filepath)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

# Detect faces in the image
faces = detector(gray)

if len(faces) == 0:
return "No faces detected in the image"

# Process each face in the image
emotions = []
for face in faces:
# Extract the region of interest (ROI) where the face is
x, y, w, h = (face.left(), face.top(), face.width(), face.height())
roi = image[y:y+h, x:x+w]

# Detect emotions for the detected face using FER
emotion, score = emotion_detector.top_emotion(roi)
emotions.append((emotion, score))

# Analyze emotions
if emotions:
# Sort by the highest emotion score
most_common_emotion = max(emotions, key=lambda x: x[1])
emotion, score = most_common_emotion
message = f"The most prominent emotion detected is {emotion} with a confidence score of {score:.2f}."
else:
message = "No emotion detected"

return render_template('result.html', message=message)

return "File upload failed"

if __name__ == '__main__':
app.run(debug=True)
Binary file added DepressionDetection/static/.DS_Store
Binary file not shown.
28 changes: 28 additions & 0 deletions DepressionDetection/templates/index.html
Nikhil210206 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Depression Detection</title>
</head>
<body style="background-color:#f4f4f4; padding:20px; font-family: Arial, sans-serif;">
<h2 style="text-align:center;">Depression Detection System</h2>

<!-- Form for file upload -->
<form action="/submit" method="post" enctype="multipart/form-data">
<div style="text-align:center; margin-bottom:20px;">
<label for="chat_file">Upload Chat File:</label><br>
<input type="file" name="chat_file" id="chat_file" accept=".txt, .csv"><br>
</div>

<div style="text-align:center; margin-bottom:20px;">
<label for="image_file">Upload Image (for Face Emotion Detection):</label><br>
<input type="file" name="image_file" id="image_file" accept="image/*"><br>
</div>

<div style="text-align:center; margin-top:20px;">
<input type="submit" value="Submit">
</div>
</form>
</body>
</html>
12 changes: 12 additions & 0 deletions DepressionDetection/templates/result.html
Nikhil210206 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Upload Result</title>
</head>
<body>
<h1>{{ message }}</h1>
<a href="/">Go Back</a>
</body>
</html>
Binary file added data/Refute C.docx
Nikhil210206 marked this conversation as resolved.
Show resolved Hide resolved
Binary file not shown.
Loading