Spaces:
Sleeping
Sleeping
File size: 4,990 Bytes
358916c bd16f42 358916c dc0ba93 bd16f42 358916c dc0ba93 bd16f42 dc0ba93 358916c bd16f42 dc0ba93 358916c dc0ba93 bd16f42 358916c dc0ba93 358916c bd16f42 a9e93cc bd16f42 a9e93cc bd16f42 a9e93cc dc0ba93 bd16f42 dc0ba93 bd16f42 | 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
from PIL import Image
import numpy as np
import cv2
from deepface import DeepFace
import pandas as pd
# --- পেজ কনফিগারেশন ---
st.set_page_config(page_title="Advanced Face Analyzer", layout="wide")
# --- মূল ইন্টারফেস ---
st.title("🔍 Advanced AI Face Analyzer")
st.write("আপলোড করা ছবিতে মুখ বিশ্লেষণ করে বয়স, লিঙ্গ, এবং বিভিন্ন মডেল ব্যবহার করে আবেগ বের করা হয়।")
st.write("---")
# --- সাইডবার ---
st.sidebar.header("⚙️ সেটিংস")
# বিভিন্ন মডেল থেকে বেছে নেওয়ার অপশন
emotion_model = st.sidebar.selectbox(
"আবেগ বিশ্লেষণের জন্য একটি মডেল বেছে নিন:",
("VGG-Face", "Facenet", "DeepFace", "ArcFace", "Dlib"),
index=2 # ডিফল্ট হিসেবে 'DeepFace' মডেল
)
# --- ফাইল আপলোডার ---
uploaded_file = st.file_uploader("📤 একটি ছবি আপলোড করুন", type=["jpg", "png", "jpeg"])
if uploaded_file is not None:
try:
col1, col2 = st.columns(2)
with col1:
# ছবিটি ওপেন এবং ডিসপ্লে করা
image = Image.open(uploaded_file)
st.image(image, caption="আপলোড করা ছবি", use_column_width=True)
# ইমেজটিকে OpenCV ফরম্যাটে রূপান্তর করা
img_array = np.array(image.convert("RGB"))
img_bgr = cv2.cvtColor(img_array, cv2.COLOR_RGB2BGR)
with col2:
# DeepFace দিয়ে বিশ্লেষণ করা
with st.spinner(f"`{emotion_model}` মডেল ব্যবহার করে মুখ বিশ্লেষণ করা হচ্ছে..."):
results = DeepFace.analyze(
img_path=img_bgr,
actions=['age', 'gender', 'emotion'],
models={'emotion': emotion_model}, # ইউজারের বেছে নেওয়া মডেল ব্যবহার
enforce_detection=False
)
# ফলাফল চেক এবং প্রদর্শন
if results and isinstance(results, list) and len(results) > 0:
result = results[0]
# জেন্ডার অনুবাদ
gender = "পুরুষ (Male)" if result.get('dominant_gender') == 'Man' else "মহিলা (Female)"
st.subheader("📊 বিশ্লেষণ ফলাফল:")
st.markdown(f"""
- **👤 আনুমানিক বয়স:** `{result.get('age', 'N/A')}`
- **🚻 লিঙ্গ:** `{gender}`
- **😊 প্রধান আবেগ:** `{result.get('dominant_emotion', 'N/A').capitalize()}`
""")
st.write("---")
# আবেগের বিস্তারিত স্কোর দেখানো
st.subheader("ემოციების დეტალური ანალიზი (Emotion Score Details):")
emotion_scores = result.get('emotion', {})
if emotion_scores:
# DataFrame তৈরি করা
df_emotions = pd.DataFrame(emotion_scores.items(), columns=['আবেগ (Emotion)', 'স্কোর (Score %)'
])
df_emotions['স্কোর (Score %)'] = df_emotions['স্কোর (Score %)'].round(2)
# বার চার্ট দেখানো
st.dataframe(df_emotions.style.highlight_max(subset=['স্কোর (Score %)'], color='lightgreen'))
st.bar_chart(df_emotions.set_index('আবেগ (Emotion)'))
else:
st.write("আবেগের বিস্তারিত স্কোর পাওয়া যায়নি।")
else:
st.warning("⚠️ দুঃখিত, এই ছবিতে কোনো মুখ খুঁজে পাওয়া যায়নি।")
except Exception as e:
st.error(f"❌ একটি অপ্রত্যাশিত সমস্যা হয়েছে: {e}")
st.info("অন্য মডেল বা অন্য ছবি চেষ্টা করে দেখতে পারেন।")
else:
st.info("শুরু করতে, একটি ছবি আপলোড করুন এবং সাইডবার থেকে সেটিংস পরিবর্তন করুন।") |