Spaces:
Sleeping
Sleeping
File size: 2,666 Bytes
0e2dc1c b1c40bb 9d3fe6e 0e2dc1c b1c40bb 0e2dc1c b1c40bb 0e2dc1c b1c40bb 0e2dc1c b1c40bb e0b5771 18ef570 0e2dc1c b1c40bb 0e2dc1c b1c40bb 79e36d5 18ef570 b1c40bb 18ef570 0e2dc1c e0b5771 18ef570 b1c40bb 18ef570 b1c40bb 18ef570 b1c40bb 18ef570 b1c40bb 18ef570 0e2dc1c 18ef570 b1c40bb 18ef570 b1c40bb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
import streamlit as st
import random
from gradio_client import Client, file
# ====================================
# Example Ayahs
# ====================================
ayahs = {
"sad": [
{
"ayah": "2:286",
"arabic": "ููุง ููููููููู ุงูููููู ููููุณูุง ุฅููููุง ููุณูุนูููุง",
"translation": "Allah does not burden a soul beyond that it can bear.",
"tafsir": "Every test is within your capacity, with Allahโs help."
}
],
"happy": [
{
"ayah": "94:5-6",
"arabic": "ููุฅูููู ู
ูุนู ุงููุนูุณูุฑู ููุณูุฑูุง ุฅูููู ู
ูุนู ุงููุนูุณูุฑู ููุณูุฑูุง",
"translation": "Indeed, with hardship comes ease.",
"tafsir": "Your happiness is part of Allahโs ease."
}
],
"angry": [
{
"ayah": "3:134",
"arabic": "ููุงููููุงุธูู
ูููู ุงููุบูููุธู",
"translation": "Those who restrain anger...",
"tafsir": "Patience and controlling anger are rewarded."
}
]
}
# ====================================
# Streamlit UI
# ====================================
st.set_page_config(page_title="Qurโan Healing Soul - Emotion from Image", page_icon="๐")
st.title("๐ Qurโan Healing Soul - FER via API")
uploaded_file = st.file_uploader("Upload your selfie", type=["jpg", "png", "jpeg"])
if uploaded_file is not None:
# Show uploaded image
st.image(uploaded_file, caption="Uploaded Image", use_container_width=True)
st.info("Detecting emotion... please wait...")
# Save file locally
with open("temp_image.png", "wb") as f:
f.write(uploaded_file.read())
# Call Gradio API
client = Client("ElenaRyumina/face_emotion_recognition")
result = client.predict(
inp=file("temp_image.png"),
api_name="/preprocess_image_and_predict"
)
_, _, confidences = result
# Use top label directly
dominant = confidences["label"]
st.success(f"Dominant Emotion: **{dominant}**")
# Map to emotion group
dominant_lower = dominant.lower()
if dominant_lower in ["sad", "fear"]:
key = "sad"
elif dominant_lower in ["happy", "happiness", "surprise"]:
key = "happy"
elif dominant_lower in ["angry", "disgust"]:
key = "angry"
else:
key = "sad"
# Show ayah
ayah = random.choice(ayahs[key])
st.markdown(f"""
### ๐ Ayah ({ayah['ayah']})
**Arabic:** *{ayah['arabic']}*
**Translation:** {ayah['translation']}
**Tafsir:** {ayah['tafsir']}
""")
|