Skip to content

Commit

Permalink
Merge pull request #3 from Daniyalhash/main
Browse files Browse the repository at this point in the history
Front-end Updated
  • Loading branch information
saadkhi authored Aug 1, 2024
2 parents 13eadfb + b5496fd commit db0c33b
Show file tree
Hide file tree
Showing 1,309 changed files with 380,253 additions and 50 deletions.
90 changes: 40 additions & 50 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from flask import Flask, render_template, request, redirect, url_for, session
from flask import Flask, jsonify, request
from flask_cors import CORS
import cv2
import numpy as np
import mediapipe as mp
from keras.models import load_model
import webbrowser
import os

app = Flask(__name__)
CORS(app) # Enable CORS

app.secret_key = 'supersecretkey' # Set a secret key for session management

model = load_model("model.h5")
Expand All @@ -20,44 +22,34 @@
if not os.path.exists("emotion.npy"):
np.save("emotion.npy", np.array([""]))

@app.route('/', methods=['GET', 'POST'])
def index():
try:
emotion = np.load("emotion.npy")[0]
except FileNotFoundError:
emotion = ""

lang = session.get('language', '')
singer = session.get('singer', '')

if request.method == 'POST':
lang = request.form['language']
singer = request.form['singer']
session['language'] = lang
session['singer'] = singer
@app.route('/api/capture_emotion', methods=['POST'])
def api_capture_emotion():
capture_emotion()
emotion = np.load("emotion.npy")[0]
return jsonify({"emotion": emotion})
@app.route('/api/recommend', methods=['POST'])
def api_recommend():
lang = request.json.get('language')
singer = request.json.get('singer')
emotion = np.load("emotion.npy")[0]
if not emotion:
return jsonify({"warning": "Please let me capture your emotion first"})
else:
# Construct recommendation URL
search_query = f"{lang} {emotion} song {singer}"
url = f"https://www.youtube.com/results?search_query={search_query}"
np.save("emotion.npy", np.array([""]))
return jsonify({"url": url})

if 'capture' in request.form:
capture_emotion()
elif 'recommend' in request.form:
emotion = np.load("emotion.npy")[0]
if not emotion:
warning = "Please let me capture your emotion first"
return render_template('index.html', warning=warning, language=lang, singer=singer)
else:
webbrowser.open(f"https://www.youtube.com/results?search_query={lang}+{emotion}+song+{singer}")
np.save("emotion.npy", np.array([""]))
session.pop('language', None)
session.pop('singer', None)
emotion = ""

return render_template('index.html', emotion=emotion, language=lang, singer=singer)

def capture_emotion():
cap = cv2.VideoCapture(0)

while True:
ret, frame = cap.read()
if not ret:
break

frame = cv2.flip(frame, 1)
res = holis.process(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))
lst = []
Expand All @@ -67,26 +59,24 @@ def capture_emotion():
lst.append(i.x - res.face_landmarks.landmark[1].x)
lst.append(i.y - res.face_landmarks.landmark[1].y)

if res.left_hand_landmarks:
for i in res.left_hand_landmarks.landmark:
lst.append(i.x - res.left_hand_landmarks.landmark[8].x)
lst.append(i.y - res.left_hand_landmarks.landmark[8].y)
else:
for i in range(42):
lst.append(0.0)
if res.left_hand_landmarks:
for i in res.left_hand_landmarks.landmark:
lst.append(i.x - res.left_hand_landmarks.landmark[8].x)
lst.append(i.y - res.left_hand_landmarks.landmark[8].y)
else:
lst.extend([0.0] * 42) # Append zeros if landmarks are missing

if res.right_hand_landmarks:
for i in res.right_hand_landmarks.landmark:
lst.append(i.x - res.right_hand_landmarks.landmark[8].x)
lst.append(i.y - res.right_hand_landmarks.landmark[8].y)
else:
for i in range(42):
lst.append(0.0)
if res.right_hand_landmarks:
for i in res.right_hand_landmarks.landmark:
lst.append(i.x - res.right_hand_landmarks.landmark[8].x)
lst.append(i.y - res.right_hand_landmarks.landmark[8].y)
else:
lst.extend([0.0] * 42) # Append zeros if landmarks are missing

lst = np.array(lst).reshape(1, -1)
pred = label[np.argmax(model.predict(lst))]
np.save("emotion.npy", np.array([pred]))
break
lst = np.array(lst).reshape(1, -1)
pred = label[np.argmax(model.predict(lst))]
np.save("emotion.npy", np.array([pred]))
break

cap.release()
cv2.destroyAllWindows()
Expand Down
1 change: 1 addition & 0 deletions emotionweb
Submodule emotionweb added at 10d620
16 changes: 16 additions & 0 deletions node_modules/.bin/loose-envify

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions node_modules/.bin/loose-envify.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions node_modules/.bin/loose-envify.ps1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

77 changes: 77 additions & 0 deletions node_modules/.package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions node_modules/babel-runtime/.npmignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions node_modules/babel-runtime/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions node_modules/babel-runtime/core-js.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/babel-runtime/core-js/array/concat.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/babel-runtime/core-js/array/copy-within.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/babel-runtime/core-js/array/entries.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/babel-runtime/core-js/array/every.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/babel-runtime/core-js/array/fill.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/babel-runtime/core-js/array/filter.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/babel-runtime/core-js/array/find-index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/babel-runtime/core-js/array/find.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/babel-runtime/core-js/array/for-each.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/babel-runtime/core-js/array/from.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/babel-runtime/core-js/array/includes.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/babel-runtime/core-js/array/index-of.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/babel-runtime/core-js/array/join.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/babel-runtime/core-js/array/keys.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/babel-runtime/core-js/array/last-index-of.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/babel-runtime/core-js/array/map.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/babel-runtime/core-js/array/of.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/babel-runtime/core-js/array/pop.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/babel-runtime/core-js/array/push.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/babel-runtime/core-js/array/reduce-right.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/babel-runtime/core-js/array/reduce.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/babel-runtime/core-js/array/reverse.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/babel-runtime/core-js/array/shift.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/babel-runtime/core-js/array/slice.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/babel-runtime/core-js/array/some.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/babel-runtime/core-js/array/sort.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/babel-runtime/core-js/array/splice.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/babel-runtime/core-js/array/turn.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/babel-runtime/core-js/array/unshift.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/babel-runtime/core-js/array/values.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/babel-runtime/core-js/clear-immediate.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/babel-runtime/core-js/date/add-locale.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/babel-runtime/core-js/date/format-utc.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/babel-runtime/core-js/date/format.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/babel-runtime/core-js/error/is-error.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/babel-runtime/core-js/function/only.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/babel-runtime/core-js/function/part.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/babel-runtime/core-js/get-iterator.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/babel-runtime/core-js/is-iterable.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit db0c33b

Please sign in to comment.