Spaces:
Runtime error
Runtime error
File size: 7,752 Bytes
db2e8d3 |
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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
import streamlit as st
import subprocess
import time
import pandas as pd
import plotly.express as px
import random
from datetime import datetime
from sklearn.linear_model import LogisticRegression
from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
# کلاس برای یادگیری ماشین
class MLEngine:
def __init__(self):
# ایجاد دادههای آموزشی شبیهسازی شده
self.X, self.y = make_classification(n_samples=1000, n_features=10, random_state=42)
self.model = LogisticRegression()
self.training_history = []
self.last_update_time = None
self.current_accuracy = 0
self.total_interactions = 1234
self.user_satisfaction = 95
def train_model(self):
"""آموزش مدل و ذخیره دقت آن"""
# تقسیم دادهها به مجموعههای آموزشی و آزمایشی
X_train, X_test, y_train, y_test = train_test_split(self.X, self.y, test_size=0.2, random_state=42)
self.model.fit(X_train, y_train)
# پیشبینی و محاسبه دقت
predictions = self.model.predict(X_test)
accuracy = accuracy_score(y_test, predictions)
# ذخیره دقت در تاریخچه آموزشی
self.current_accuracy = accuracy * 100 # دقت به درصد
self.training_history.append({"timestamp": datetime.now(), "accuracy": self.current_accuracy})
self.last_update_time = datetime.now()
def update_knowledge_base(self):
"""شبیهسازی بهروزرسانی پایگاه دانش"""
time.sleep(2) # شبیهسازی زمان بهروزرسانی پایگاه دانش
self.train_model() # آموزش مجدد مدل به عنوان بخشی از بهروزرسانی
def get_learning_stats(self):
"""برگرداندن آمار یادگیری شامل دقت و تاریخچه آموزشی"""
return {
"history": self.training_history,
"currentAccuracy": self.current_accuracy,
"totalInteractions": self.total_interactions,
"userSatisfaction": self.user_satisfaction,
"lastUpdate": self.last_update_time.strftime("%Y-%m-%d %H:%M:%S") if self.last_update_time else "No Update Yet"
}
# ایجاد یک نمونه از کلاس MLEngine
ml_engine = MLEngine()
ml_engine.train_model() # آموزش اولیه مدل
# تابع برای اجرای فایل `admin_dashboard_filemanager.py`
def open_file_manager():
"""اجرای فایل مدیریت فایلها و بهروزرسانی پایگاه دانش"""
try:
# اجرای فایل `admin_dashboard_filemanager.py`
subprocess.Popen(["python", "admin_dashboard_filemanager.py"])
st.success("Knowledge Base update has been initiated successfully!")
except Exception as e:
st.error(f"Error while opening file manager: {e}")
# CSS سفارشی برای طراحی گلس مورفیسم و نئومورفیسم
CUSTOM_CSS = """
<style>
body {
background: linear-gradient(135deg, #ece9e6, #ffffff);
font-family: 'Arial', sans-serif;
}
.dashboard-container {
max-width: 800px;
margin: auto;
padding: 20px;
}
.glass-card, .glass-button, .glass-chart {
backdrop-filter: blur(10px); /* شفافیت پسزمینه */
background: rgba(255, 255, 255, 0.15); /* پسزمینه شفاف */
border-radius: 20px; /* گوشههای گرد */
box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.15), -4px -4px 10px rgba(255, 255, 255, 0.7); /* سایههای نئومورفیسم */
padding: 20px;
margin: 15px 0;
transition: all 0.3s ease;
}
.glass-card:hover, .glass-button:hover {
box-shadow: 6px 6px 12px rgba(0, 0, 0, 0.2), -6px -6px 12px rgba(255, 255, 255, 0.5); /* افکت سایه هنگام هاور */
transform: translateY(-5px); /* جابجایی جزئی */
}
.header {
text-align: center;
color: #333;
font-size: 24px;
font-weight: bold;
padding: 10px 0;
}
.glass-button {
display: inline-block;
color: #ffffff;
background: linear-gradient(135deg, #4a90e2, #50e3c2);
border: none;
font-size: 18px;
cursor: pointer;
text-align: center;
width: 100%;
padding: 10px 20px;
margin-top: 10px;
border-radius: 20px;
box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.15), -4px -4px 10px rgba(255, 255, 255, 0.7); /* سایههای نئومورفیسم */
transition: all 0.3s ease;
}
.glass-button:hover {
background: linear-gradient(135deg, #50e3c2, #4a90e2); /* تغییر رنگ هنگام هاور */
}
.stat-card {
text-align: center;
color: #333;
padding: 15px;
}
.stat-title {
font-size: 16px;
color: #666;
}
.stat-value {
font-size: 26px;
font-weight: bold;
color: #4a90e2;
}
.glass-upload {
background: rgba(255, 255, 255, 0.25); /* پسزمینه شفاف */
border: 1px solid rgba(255, 255, 255, 0.3);
border-radius: 20px;
padding: 20px;
box-shadow: inset 4px 4px 6px rgba(0, 0, 0, 0.1), inset -4px -4px 6px rgba(255, 255, 255, 0.5); /* سایه داخلی */
}
.icon {
font-size: 24px;
color: #4a90e2;
margin-right: 8px;
}
</style>
"""
# اعمال CSS سفارشی
st.markdown(CUSTOM_CSS, unsafe_allow_html=True)
# ساخت داشبورد
st.markdown("<div class='dashboard-container'>", unsafe_allow_html=True)
st.markdown("<div class='header'>Admin Dashboard</div>", unsafe_allow_html=True)
# دکمه بهروزرسانی پایگاه دانش با طراحی گلس مورفیسم
if st.button("Update Knowledge Base"):
ml_engine.update_knowledge_base()
open_file_manager()
# نمایش آمارها با طراحی نئومورفیسم
st.subheader("Statistics")
col1, col2, col3 = st.columns(3)
# نمایش آمارهای فعلی مدل
stats = ml_engine.get_learning_stats()
col1.markdown(f"<div class='glass-card stat-card'><div class='stat-title'>📊 Accuracy</div><div class='stat-value'>{stats['currentAccuracy']:.2f}%</div></div>", unsafe_allow_html=True)
col2.markdown(f"<div class='glass-card stat-card'><div class='stat-title'>👤 Total Interactions</div><div class='stat-value'>{stats['totalInteractions']}</div></div>", unsafe_allow_html=True)
col3.markdown(f"<div class='glass-card stat-card'><div class='stat-title'>👍 User Satisfaction</div><div class='stat-value'>{stats['userSatisfaction']}%</div></div>", unsafe_allow_html=True)
# نمودار روند یادگیری با طراحی شفاف (گلس مورفیسم)
st.subheader("Learning Rate Trend")
learning_df = pd.DataFrame([
{"Date": stat["timestamp"], "Accuracy": stat["accuracy"]}
for stat in stats["history"]
])
fig = px.line(learning_df, x="Date", y="Accuracy", title="Learning Rate Over Time",
template="plotly_white", markers=True)
fig.update_traces(line=dict(color="#4a90e2", width=2))
st.plotly_chart(fig, use_container_width=True)
# آپلود فایل با طراحی نئومورفیسم
st.subheader("Manage Files")
st.markdown("<div class='glass-upload'>", unsafe_allow_html=True)
uploaded_file = st.file_uploader("Upload Document", type=["txt", "pdf", "docx"])
if uploaded_file:
st.success("File uploaded successfully!")
st.markdown("</div>", unsafe_allow_html=True)
# پایان داشبورد
st.markdown("</div>", unsafe_allow_html=True)
|