Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,11 @@
|
|
1 |
import streamlit as st
|
2 |
-
from gradio_client import Client, file
|
3 |
-
import tempfile
|
4 |
import random
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
-
# --- Your Qur’an ayahs ---
|
7 |
ayahs = {
|
8 |
"sad": [
|
9 |
{
|
@@ -31,50 +33,57 @@ ayahs = {
|
|
31 |
]
|
32 |
}
|
33 |
|
34 |
-
#
|
35 |
-
|
36 |
-
|
37 |
-
st.title("🌙 Qur’an Healing Soul - Emotion from Image")
|
38 |
-
|
39 |
-
uploaded_file = st.file_uploader("Upload your selfie", type=["jpg", "jpeg", "png"])
|
40 |
|
41 |
-
|
42 |
-
|
43 |
|
44 |
-
|
45 |
-
tmp_file.write(uploaded_file.read())
|
46 |
-
tmp_file_path = tmp_file.name
|
47 |
|
|
|
|
|
|
|
48 |
st.info("Detecting emotion... please wait...")
|
49 |
|
50 |
-
#
|
51 |
-
|
|
|
52 |
|
|
|
|
|
53 |
result = client.predict(
|
54 |
-
inp=file(
|
55 |
api_name="/preprocess_image_and_predict"
|
56 |
)
|
57 |
|
58 |
-
|
59 |
-
_, _, confidences = result
|
60 |
|
|
|
|
|
|
|
|
|
|
|
61 |
st.subheader("Emotion Probabilities")
|
62 |
st.json(confidences)
|
63 |
|
64 |
-
#
|
65 |
-
dominant =
|
66 |
st.success(f"Dominant Emotion: **{dominant}**")
|
67 |
|
68 |
-
# Map emotion
|
69 |
-
|
|
|
70 |
key = "sad"
|
71 |
-
elif
|
72 |
key = "happy"
|
73 |
-
elif
|
74 |
key = "angry"
|
75 |
else:
|
76 |
key = "sad"
|
77 |
|
|
|
78 |
ayah = random.choice(ayahs[key])
|
79 |
st.markdown(f"""
|
80 |
### 📖 Ayah ({ayah['ayah']})
|
@@ -85,3 +94,4 @@ if uploaded_file:
|
|
85 |
|
86 |
**Tafsir:** {ayah['tafsir']}
|
87 |
""")
|
|
|
|
1 |
import streamlit as st
|
|
|
|
|
2 |
import random
|
3 |
+
from gradio_client import Client, file
|
4 |
+
|
5 |
+
# ====================================
|
6 |
+
# Example Ayahs
|
7 |
+
# ====================================
|
8 |
|
|
|
9 |
ayahs = {
|
10 |
"sad": [
|
11 |
{
|
|
|
33 |
]
|
34 |
}
|
35 |
|
36 |
+
# ====================================
|
37 |
+
# Streamlit UI
|
38 |
+
# ====================================
|
|
|
|
|
|
|
39 |
|
40 |
+
st.set_page_config(page_title="Qur’an Healing Soul - Emotion from Image", page_icon="🌙")
|
41 |
+
st.title("🌙 Qur’an Healing Soul - FER via API")
|
42 |
|
43 |
+
uploaded_file = st.file_uploader("Upload your selfie", type=["jpg", "png", "jpeg"])
|
|
|
|
|
44 |
|
45 |
+
if uploaded_file is not None:
|
46 |
+
# Show uploaded image
|
47 |
+
st.image(uploaded_file, caption="Uploaded Image", use_column_width=True)
|
48 |
st.info("Detecting emotion... please wait...")
|
49 |
|
50 |
+
# Save file locally
|
51 |
+
with open("temp_image.png", "wb") as f:
|
52 |
+
f.write(uploaded_file.read())
|
53 |
|
54 |
+
# Call Gradio API
|
55 |
+
client = Client("ElenaRyumina/Facial_Expression_Recognition")
|
56 |
result = client.predict(
|
57 |
+
inp=file("temp_image.png"),
|
58 |
api_name="/preprocess_image_and_predict"
|
59 |
)
|
60 |
|
61 |
+
face_image, heatmap_image, confidences = result
|
|
|
62 |
|
63 |
+
# Show face & heatmap
|
64 |
+
st.image(face_image, caption="Detected Face", use_column_width=True)
|
65 |
+
st.image(heatmap_image, caption="Heatmap", use_column_width=True)
|
66 |
+
|
67 |
+
# Show probabilities
|
68 |
st.subheader("Emotion Probabilities")
|
69 |
st.json(confidences)
|
70 |
|
71 |
+
# Use top label directly
|
72 |
+
dominant = confidences["label"]
|
73 |
st.success(f"Dominant Emotion: **{dominant}**")
|
74 |
|
75 |
+
# Map to emotion group
|
76 |
+
dominant_lower = dominant.lower()
|
77 |
+
if dominant_lower in ["sad", "fear"]:
|
78 |
key = "sad"
|
79 |
+
elif dominant_lower in ["happy", "happiness", "surprise"]:
|
80 |
key = "happy"
|
81 |
+
elif dominant_lower in ["angry", "disgust"]:
|
82 |
key = "angry"
|
83 |
else:
|
84 |
key = "sad"
|
85 |
|
86 |
+
# Show ayah
|
87 |
ayah = random.choice(ayahs[key])
|
88 |
st.markdown(f"""
|
89 |
### 📖 Ayah ({ayah['ayah']})
|
|
|
94 |
|
95 |
**Tafsir:** {ayah['tafsir']}
|
96 |
""")
|
97 |
+
|