Spaces:
Sleeping
Sleeping
| # app.py | |
| import streamlit as st | |
| from transformers import pipeline | |
| import random | |
| # โ โ Must be FIRST! | |
| st.set_page_config(page_title="Qurโan Healing Soul - Text Emotion", page_icon="๐") | |
| # Quranic ayahs dataset mapped to emotions | |
| 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." | |
| } | |
| ] | |
| } | |
| # Load pre-trained sentiment-analysis pipeline | |
| def load_pipeline(): | |
| return pipeline("sentiment-analysis") | |
| nlp = load_pipeline() | |
| # UI | |
| st.title("๐ Qurโan Healing Soul - Text Emotion") | |
| st.write("Share how you feel in your own words, and receive an ayah for healing.") | |
| user_input = st.text_area("โ๏ธ How are you feeling today?") | |
| if st.button("Analyze"): | |
| if user_input.strip() == "": | |
| st.warning("Please write something about how you feel.") | |
| else: | |
| result = nlp(user_input)[0] | |
| label = result['label'].lower() | |
| score = result['score'] | |
| st.info(f"**Detected Sentiment:** `{label}` ({round(score*100, 2)}%)") | |
| # Very basic mapping: map sentiment to emotion group | |
| if "negative" in label or "sad" in label: | |
| key = "sad" | |
| elif "positive" in label or "happy" in label: | |
| key = "happy" | |
| elif "angry" in label: | |
| key = "angry" | |
| else: | |
| key = "sad" | |
| ayah = random.choice(ayahs[key]) | |
| st.markdown(f""" | |
| **๐ Ayah ({ayah['ayah']})** | |
| Arabic: *{ayah['arabic']}* | |
| Translation: {ayah['translation']} | |
| Tafsir: {ayah['tafsir']} | |
| """) | |