aimyrajpoot commited on
Commit
9ca958a
·
verified ·
1 Parent(s): c88a28c

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +50 -0
  2. emotion_model.h5 +3 -0
  3. requirements.txt +7 -0
app.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import gradio as gr
3
+ import numpy as np
4
+ import cv2
5
+ from tensorflow.keras.models import load_model
6
+ from gtts import gTTS
7
+ import os
8
+ import random
9
+ import requests
10
+
11
+ # Load model
12
+ model = load_model("emotion_model.h5")
13
+ emotion_labels = ['Angry', 'Disgust', 'Fear', 'Happy', 'Sad', 'Surprise', 'Neutral']
14
+
15
+ quotes = {
16
+ 'Happy': ["Keep shining!", "You look great!"],
17
+ 'Sad': ["Better days are coming.", "Stay strong."],
18
+ 'Angry': ["Take a deep breath.", "Calm down, champ."],
19
+ 'Surprise': ["Wow! Didn't expect that."],
20
+ 'Fear': ["You're safe.", "Be brave!"],
21
+ 'Disgust': ["Let it go."],
22
+ 'Neutral': ["Stay focused."]
23
+ }
24
+
25
+ def get_weather(city='Islamabad'):
26
+ api_key = "your_openweather_api_key"
27
+ url = f"http://api.openweathermap.org/data/2.5/weather?q={city}&appid={api_key}&units=metric"
28
+ try:
29
+ data = requests.get(url).json()
30
+ return f"{data['main']['temp']}°C, {data['weather'][0]['description']}"
31
+ except:
32
+ return "Weather unavailable"
33
+
34
+ def detect_emotion(image):
35
+ gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
36
+ resized = cv2.resize(gray, (48, 48)).reshape(1, 48, 48, 1) / 255.0
37
+ pred = model.predict(resized)
38
+ emotion = emotion_labels[np.argmax(pred)]
39
+ quote = random.choice(quotes[emotion])
40
+ weather = get_weather()
41
+ return f"Emotion: {emotion}\nQuote: {quote}\nWeather: {weather}"
42
+
43
+ interface = gr.Interface(
44
+ fn=detect_emotion,
45
+ inputs=gr.Image(type="numpy", label="Upload Face Image"),
46
+ outputs="text",
47
+ title="Smart Mirror Emotion Detector"
48
+ )
49
+
50
+ interface.launch()
emotion_model.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:75ab46e587da3fc851be06b0c39604759b9e778b8bb719905d39feb11a9bec3d
3
+ size 10111040
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+
2
+ gradio
3
+ tensorflow
4
+ opencv-python
5
+ gTTS
6
+ matplotlib
7
+ requests