Spaces:
Sleeping
Sleeping
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']} | |
""") | |