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