Spaces:
Sleeping
Sleeping
File size: 2,436 Bytes
5acf4ff c79b849 5acf4ff | 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 | # 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
@st.cache_resource
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']}
""")
|