| #!/usr/bin/env python3 | |
| """ | |
| داشبورد تعاملی برای سیستمهای RAG و حافظه | |
| این فایل شامل داشبورد تعاملی با Dash برای نمایش نتایج است | |
| """ | |
| import os | |
| import json | |
| import asyncio | |
| import logging | |
| import time | |
| import numpy as np | |
| import pandas as pd | |
| from typing import Dict, List, Tuple, Any, Optional, Union | |
| from dataclasses import dataclass, field | |
| from datetime import datetime, timedelta | |
| import pickle | |
| from pathlib import Path | |
| # Dash imports | |
| import dash | |
| from dash import dcc, html, Input, Output, State, callback_context | |
| import plotly.graph_objects as go | |
| import plotly.express as px | |
| from plotly.subplots import make_subplots | |
| # LangChain imports | |
| from langchain_google_genai import ChatGoogleGenerativeAI, GoogleGenerativeAIEmbeddings | |
| from langchain.schema import Document | |
| from langchain.text_splitter import RecursiveCharacterTextSplitter | |
| from langchain.chains import RetrievalQA | |
| from langchain.memory import ConversationBufferMemory | |
| # Vector stores | |
| from langchain_chroma import Chroma | |
| from langchain_community.vectorstores import FAISS | |
| # تنظیمات لاگ | |
| logging.basicConfig( | |
| level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s" | |
| ) | |
| logger = logging.getLogger(__name__) | |
| class DashboardConfig: | |
| """تنظیمات داشبورد""" | |
| # Gemini API settings | |
| gemini_api_key: str = "" | |
| gemini_model: str = "gemini-1.5-pro" | |
| temperature: float = 0.7 | |
| # Dashboard settings | |
| port: int = 8050 | |
| host: str = "127.0.0.1" | |
| debug: bool = True | |
| # Data settings | |
| results_directory: str = "benchmark_results" | |
| sample_data_size: int = 100 | |
| # UI settings | |
| refresh_interval: int = 5000 # milliseconds | |
| theme: str = "BOOTSTRAP" | |
| class InteractiveRAGSystem: | |
| """سیستم RAG تعاملی برای داشبورد""" | |
| def __init__(self, config: DashboardConfig): | |
| self.config = config | |
| self.llm = ChatGoogleGenerativeAI( | |
| model=config.gemini_model, | |
| temperature=config.temperature, | |
| google_api_key=config.gemini_api_key, | |
| ) | |
| self.embeddings = GoogleGenerativeAIEmbeddings( | |
| model="models/embedding-001", google_api_key=config.gemini_api_key | |
| ) | |
| self.text_splitter = RecursiveCharacterTextSplitter( | |
| chunk_size=1000, chunk_overlap=200 | |
| ) | |
| self.vector_store = None | |
| self.qa_chain = None | |
| self.memory = ConversationBufferMemory( | |
| memory_key="chat_history", return_messages=True | |
| ) | |
| # Performance metrics | |
| self.query_history = [] | |
| self.performance_metrics = [] | |
| self._setup_knowledge_base() | |
| def _setup_knowledge_base(self): | |
| """راهاندازی پایگاه دانش""" | |
| # Sample knowledge base | |
| sample_docs = [ | |
| Document( | |
| page_content="هوش مصنوعی (AI) شاخهای از علوم کامپیوتر است که به ایجاد سیستمهایی میپردازد که قادر به انجام وظایفی هستند که معمولاً نیاز به هوش انسانی دارند.", | |
| metadata={"topic": "هوش مصنوعی", "source": "sample"}, | |
| ), | |
| Document( | |
| page_content="یادگیری ماشین (Machine Learning) زیرشاخهای از هوش مصنوعی است که به کامپیوترها امکان یادگیری از دادهها بدون برنامهنویسی صریح را میدهد.", | |
| metadata={"topic": "یادگیری ماشین", "source": "sample"}, | |
| ), | |
| Document( | |
| page_content="پردازش زبان طبیعی (NLP) شاخهای از هوش مصنوعی است که به کامپیوترها امکان درک و تولید زبان انسانی را میدهد.", | |
| metadata={"topic": "پردازش زبان طبیعی", "source": "sample"}, | |
| ), | |
| Document( | |
| page_content="بینایی کامپیوتر (Computer Vision) شاخهای از هوش مصنوعی است که به کامپیوترها امکان درک و تفسیر اطلاعات بصری را میدهد.", | |
| metadata={"topic": "بینایی کامپیوتر", "source": "sample"}, | |
| ), | |
| Document( | |
| page_content="رباتیک (Robotics) شاخهای از مهندسی است که با طراحی، ساخت و برنامهنویسی رباتها سروکار دارد.", | |
| metadata={"topic": "رباتیک", "source": "sample"}, | |
| ), | |
| ] | |
| # Create vector store | |
| self.vector_store = Chroma.from_documents( | |
| sample_docs, self.embeddings, persist_directory="./dashboard_vector_store" | |
| ) | |
| # Create QA chain | |
| retriever = self.vector_store.as_retriever(search_kwargs={"k": 3}) | |
| self.qa_chain = RetrievalQA.from_chain_type( | |
| llm=self.llm, | |
| chain_type="stuff", | |
| retriever=retriever, | |
| return_source_documents=True, | |
| ) | |
| logger.info("Interactive RAG system initialized") | |
| def query(self, question: str) -> Dict[str, Any]: | |
| """پرسش از سیستم RAG""" | |
| start_time = time.time() | |
| try: | |
| result = self.qa_chain.invoke({"query": question}) | |
| response_time = time.time() - start_time | |
| # Record query history | |
| query_record = { | |
| "timestamp": datetime.now(), | |
| "question": question, | |
| "response": result["result"], | |
| "response_time": response_time, | |
| "sources_count": len(result["source_documents"]), | |
| "response_length": len(result["result"]), | |
| } | |
| self.query_history.append(query_record) | |
| # Record performance metrics | |
| self.performance_metrics.append( | |
| { | |
| "timestamp": datetime.now(), | |
| "response_time": response_time, | |
| "sources_count": len(result["source_documents"]), | |
| "response_length": len(result["result"]), | |
| } | |
| ) | |
| return { | |
| "answer": result["result"], | |
| "sources": result["source_documents"], | |
| "response_time": response_time, | |
| "success": True, | |
| } | |
| except Exception as e: | |
| logger.error(f"Query failed: {e}") | |
| return { | |
| "answer": f"خطا در پردازش پرسش: {str(e)}", | |
| "sources": [], | |
| "response_time": time.time() - start_time, | |
| "success": False, | |
| } | |
| def get_performance_summary(self) -> Dict[str, Any]: | |
| """دریافت خلاصه عملکرد""" | |
| if not self.performance_metrics: | |
| return {} | |
| df = pd.DataFrame(self.performance_metrics) | |
| return { | |
| "total_queries": len(self.performance_metrics), | |
| "avg_response_time": df["response_time"].mean(), | |
| "avg_sources_count": df["sources_count"].mean(), | |
| "avg_response_length": df["response_length"].mean(), | |
| "recent_queries": self.query_history[-5:] if self.query_history else [], | |
| } | |
| class DashboardDataManager: | |
| """مدیر دادههای داشبورد""" | |
| def __init__(self, config: DashboardConfig): | |
| self.config = config | |
| self.sample_data = self._generate_sample_data() | |
| def _generate_sample_data(self) -> Dict[str, Any]: | |
| """تولید دادههای نمونه""" | |
| # Generate sample benchmark data | |
| np.random.seed(42) | |
| # Vector store performance data | |
| vector_stores = ["ChromaDB", "FAISS", "Pinecone", "Qdrant"] | |
| vector_data = [] | |
| for store in vector_stores: | |
| vector_data.append( | |
| { | |
| "store": store, | |
| "indexing_time": np.random.uniform(0.5, 3.0), | |
| "search_time": np.random.uniform(0.1, 1.0), | |
| "memory_usage": np.random.uniform(100, 500), | |
| "accuracy": np.random.uniform(0.7, 0.95), | |
| } | |
| ) | |
| # Memory system performance data | |
| memory_types = ["Buffer", "Summary", "Window", "Token Buffer"] | |
| memory_data = [] | |
| for mem_type in memory_types: | |
| memory_data.append( | |
| { | |
| "type": mem_type, | |
| "response_time": np.random.uniform(0.5, 2.0), | |
| "coherence": np.random.uniform(0.6, 0.9), | |
| "context_usage": np.random.uniform(0.3, 0.8), | |
| "memory_efficiency": np.random.uniform(0.5, 0.9), | |
| } | |
| ) | |
| # Time series data | |
| dates = pd.date_range(start="2024-01-01", periods=30, freq="D") | |
| time_series_data = [] | |
| for date in dates: | |
| time_series_data.append( | |
| { | |
| "date": date, | |
| "queries": np.random.randint(50, 200), | |
| "avg_response_time": np.random.uniform(0.5, 2.0), | |
| "success_rate": np.random.uniform(0.85, 0.98), | |
| "memory_usage": np.random.uniform(200, 800), | |
| } | |
| ) | |
| return { | |
| "vector_stores": vector_data, | |
| "memory_systems": memory_data, | |
| "time_series": time_series_data, | |
| "last_updated": datetime.now().isoformat(), | |
| } | |
| def get_vector_store_data(self) -> pd.DataFrame: | |
| """دریافت دادههای vector stores""" | |
| return pd.DataFrame(self.sample_data["vector_stores"]) | |
| def get_memory_system_data(self) -> pd.DataFrame: | |
| """دریافت دادههای سیستمهای حافظه""" | |
| return pd.DataFrame(self.sample_data["memory_systems"]) | |
| def get_time_series_data(self) -> pd.DataFrame: | |
| """دریافت دادههای سری زمانی""" | |
| return pd.DataFrame(self.sample_data["time_series"]) | |
| class InteractiveDashboard: | |
| """داشبورد تعاملی""" | |
| def __init__(self, config: DashboardConfig): | |
| self.config = config | |
| self.app = dash.Dash( | |
| __name__, | |
| external_stylesheets=["https://codepen.io/chriddyp/pen/bWLwgP.css"], | |
| ) | |
| self.data_manager = DashboardDataManager(config) | |
| self.rag_system = InteractiveRAGSystem(config) | |
| self._setup_layout() | |
| self._setup_callbacks() | |
| logger.info("Interactive Dashboard initialized") | |
| def _setup_layout(self): | |
| """راهاندازی layout داشبورد""" | |
| self.app.layout = html.Div( | |
| [ | |
| # Header | |
| html.Div( | |
| [ | |
| html.H1( | |
| "🚀 سیستمهای RAG و حافظه پیشرفته", | |
| className="text-center", | |
| style={"margin": "20px"}, | |
| ), | |
| html.P( | |
| "داشبورد تعاملی برای آزمایش و تحلیل سیستمهای RAG و حافظه", | |
| className="text-center text-muted", | |
| ), | |
| ], | |
| className="container-fluid", | |
| ), | |
| # Navigation tabs | |
| dcc.Tabs( | |
| id="main-tabs", | |
| value="overview", | |
| children=[ | |
| dcc.Tab(label="📊 نمای کلی", value="overview"), | |
| dcc.Tab(label="🗄️ Vector Stores", value="vector-stores"), | |
| dcc.Tab(label="🧠 سیستمهای حافظه", value="memory-systems"), | |
| dcc.Tab(label="🤖 RAG تعاملی", value="interactive-rag"), | |
| dcc.Tab(label="📈 تحلیل عملکرد", value="performance-analysis"), | |
| ], | |
| ), | |
| # Tab content | |
| html.Div(id="tab-content"), | |
| # Auto-refresh interval | |
| dcc.Interval( | |
| id="interval-component", | |
| interval=self.config.refresh_interval, | |
| n_intervals=0, | |
| ), | |
| ] | |
| ) | |
| def _setup_callbacks(self): | |
| """راهاندازی callbacks""" | |
| def render_tab_content(active_tab): | |
| """رندر محتوای تبها""" | |
| if active_tab == "overview": | |
| return self._create_overview_tab() | |
| elif active_tab == "vector-stores": | |
| return self._create_vector_stores_tab() | |
| elif active_tab == "memory-systems": | |
| return self._create_memory_systems_tab() | |
| elif active_tab == "interactive-rag": | |
| return self._create_interactive_rag_tab() | |
| elif active_tab == "performance-analysis": | |
| return self._create_performance_analysis_tab() | |
| def handle_rag_query(n_clicks, query): | |
| """مدیریت پرسش RAG""" | |
| if not n_clicks or not query: | |
| return "", "", "" | |
| result = self.rag_system.query(query) | |
| # Format response | |
| response = html.Div( | |
| [ | |
| html.H5("پاسخ:"), | |
| html.P(result["answer"], className="alert alert-info"), | |
| ] | |
| ) | |
| # Format sources | |
| sources = html.Div( | |
| [ | |
| html.H5("منابع:"), | |
| html.Ul( | |
| [ | |
| html.Li(f"منبع {i+1}: {doc.page_content[:100]}...") | |
| for i, doc in enumerate(result["sources"][:3]) | |
| ] | |
| ), | |
| ] | |
| ) | |
| # Format metrics | |
| metrics = html.Div( | |
| [ | |
| html.H5("معیارهای عملکرد:"), | |
| html.P(f"زمان پاسخ: {result['response_time']:.3f} ثانیه"), | |
| html.P(f"تعداد منابع: {len(result['sources'])}"), | |
| html.P(f"طول پاسخ: {len(result['answer'])} کاراکتر"), | |
| ] | |
| ) | |
| return response, sources, metrics | |
| def update_performance_summary(n): | |
| """بهروزرسانی خلاصه عملکرد""" | |
| summary = self.rag_system.get_performance_summary() | |
| if not summary: | |
| return html.P("هنوز پرسشی انجام نشده است") | |
| return html.Div( | |
| [ | |
| html.H5("خلاصه عملکرد:"), | |
| html.P(f"تعداد کل پرسشها: {summary['total_queries']}"), | |
| html.P( | |
| f"میانگین زمان پاسخ: {summary['avg_response_time']:.3f} ثانیه" | |
| ), | |
| html.P(f"میانگین تعداد منابع: {summary['avg_sources_count']:.1f}"), | |
| html.P( | |
| f"میانگین طول پاسخ: {summary['avg_response_length']:.0f} کاراکتر" | |
| ), | |
| ] | |
| ) | |
| def _create_overview_tab(self): | |
| """ایجاد تب نمای کلی""" | |
| return html.Div( | |
| [ | |
| html.Div( | |
| [ | |
| html.Div( | |
| [ | |
| html.H3("📊 آمار کلی"), | |
| html.Div( | |
| id="overview-stats", | |
| children=[ | |
| html.Div( | |
| [ | |
| html.H4("4", className="text-primary"), | |
| html.P("Vector Stores"), | |
| ], | |
| className="col-md-3 text-center", | |
| ), | |
| html.Div( | |
| [ | |
| html.H4("4", className="text-success"), | |
| html.P("Memory Systems"), | |
| ], | |
| className="col-md-3 text-center", | |
| ), | |
| html.Div( | |
| [ | |
| html.H4("5", className="text-info"), | |
| html.P("Knowledge Topics"), | |
| ], | |
| className="col-md-3 text-center", | |
| ), | |
| html.Div( | |
| [ | |
| html.H4( | |
| "100%", className="text-warning" | |
| ), | |
| html.P("System Status"), | |
| ], | |
| className="col-md-3 text-center", | |
| ), | |
| ], | |
| className="row", | |
| ), | |
| ], | |
| className="card-body", | |
| ) | |
| ], | |
| className="card", | |
| ), | |
| html.Br(), | |
| # Performance overview chart | |
| html.Div( | |
| [ | |
| html.H3("📈 نمای کلی عملکرد"), | |
| dcc.Graph(figure=self._create_overview_chart()), | |
| ], | |
| className="card", | |
| ), | |
| ], | |
| className="container-fluid", | |
| ) | |
| def _create_vector_stores_tab(self): | |
| """ایجاد تب Vector Stores""" | |
| return html.Div( | |
| [ | |
| html.H3("🗄️ مقایسه Vector Stores"), | |
| # Performance comparison chart | |
| dcc.Graph(figure=self._create_vector_stores_chart()), | |
| html.Br(), | |
| # Detailed metrics table | |
| html.H4("جدول معیارهای تفصیلی"), | |
| html.Div(id="vector-stores-table"), | |
| ], | |
| className="container-fluid", | |
| ) | |
| def _create_memory_systems_tab(self): | |
| """ایجاد تب سیستمهای حافظه""" | |
| return html.Div( | |
| [ | |
| html.H3("🧠 مقایسه سیستمهای حافظه"), | |
| # Memory systems comparison chart | |
| dcc.Graph(figure=self._create_memory_systems_chart()), | |
| html.Br(), | |
| # Memory efficiency chart | |
| dcc.Graph(figure=self._create_memory_efficiency_chart()), | |
| ], | |
| className="container-fluid", | |
| ) | |
| def _create_interactive_rag_tab(self): | |
| """ایجاد تب RAG تعاملی""" | |
| return html.Div( | |
| [ | |
| html.H3("🤖 سیستم RAG تعاملی"), | |
| # Query input | |
| html.Div( | |
| [ | |
| html.Label("پرسش خود را وارد کنید:"), | |
| dcc.Textarea( | |
| id="rag-input", | |
| placeholder="مثال: هوش مصنوعی چیست؟", | |
| style={"width": "100%", "height": 100}, | |
| ), | |
| html.Br(), | |
| html.Button( | |
| "پرسش", id="rag-submit", className="btn btn-primary" | |
| ), | |
| ], | |
| className="form-group", | |
| ), | |
| html.Br(), | |
| # Results | |
| html.Div( | |
| [ | |
| html.Div(id="rag-response"), | |
| html.Br(), | |
| html.Div(id="rag-sources"), | |
| html.Br(), | |
| html.Div(id="rag-metrics"), | |
| ] | |
| ), | |
| html.Br(), | |
| # Performance summary | |
| html.Div( | |
| [html.H4("خلاصه عملکرد"), html.Div(id="performance-summary")], | |
| className="card", | |
| ), | |
| ], | |
| className="container-fluid", | |
| ) | |
| def _create_performance_analysis_tab(self): | |
| """ایجاد تب تحلیل عملکرد""" | |
| return html.Div( | |
| [ | |
| html.H3("📈 تحلیل عملکرد"), | |
| # Time series chart | |
| dcc.Graph(figure=self._create_time_series_chart()), | |
| html.Br(), | |
| # Performance metrics | |
| html.Div( | |
| [ | |
| html.H4("معیارهای عملکرد"), | |
| dcc.Graph(figure=self._create_performance_metrics_chart()), | |
| ] | |
| ), | |
| ], | |
| className="container-fluid", | |
| ) | |
| def _create_overview_chart(self): | |
| """ایجاد نمودار نمای کلی""" | |
| fig = make_subplots( | |
| rows=2, | |
| cols=2, | |
| subplot_titles=( | |
| "Vector Store Performance", | |
| "Memory System Performance", | |
| "Response Time Distribution", | |
| "System Health", | |
| ), | |
| specs=[ | |
| [{"type": "bar"}, {"type": "bar"}], | |
| [{"type": "histogram"}, {"type": "indicator"}], | |
| ], | |
| ) | |
| # Vector store performance | |
| vector_data = self.data_manager.get_vector_store_data() | |
| fig.add_trace( | |
| go.Bar( | |
| x=vector_data["store"], | |
| y=vector_data["search_time"], | |
| name="Search Time", | |
| marker_color="lightblue", | |
| ), | |
| row=1, | |
| col=1, | |
| ) | |
| # Memory system performance | |
| memory_data = self.data_manager.get_memory_system_data() | |
| fig.add_trace( | |
| go.Bar( | |
| x=memory_data["type"], | |
| y=memory_data["response_time"], | |
| name="Response Time", | |
| marker_color="lightgreen", | |
| ), | |
| row=1, | |
| col=2, | |
| ) | |
| # Response time distribution | |
| time_data = self.data_manager.get_time_series_data() | |
| fig.add_trace( | |
| go.Histogram( | |
| x=time_data["avg_response_time"], name="Response Time Distribution" | |
| ), | |
| row=2, | |
| col=1, | |
| ) | |
| # System health indicator | |
| avg_success_rate = time_data["success_rate"].mean() | |
| fig.add_trace( | |
| go.Indicator( | |
| mode="gauge+number", | |
| value=avg_success_rate * 100, | |
| domain={"x": [0, 1], "y": [0, 1]}, | |
| title={"text": "System Health (%)"}, | |
| gauge={ | |
| "axis": {"range": [None, 100]}, | |
| "bar": {"color": "darkblue"}, | |
| "steps": [ | |
| {"range": [0, 50], "color": "lightgray"}, | |
| {"range": [50, 80], "color": "yellow"}, | |
| {"range": [80, 100], "color": "green"}, | |
| ], | |
| }, | |
| ), | |
| row=2, | |
| col=2, | |
| ) | |
| fig.update_layout(height=600, showlegend=False) | |
| return fig | |
| def _create_vector_stores_chart(self): | |
| """ایجاد نمودار Vector Stores""" | |
| vector_data = self.data_manager.get_vector_store_data() | |
| fig = make_subplots( | |
| rows=1, | |
| cols=2, | |
| subplot_titles=("Indexing Time", "Search Time"), | |
| specs=[[{"type": "bar"}, {"type": "bar"}]], | |
| ) | |
| fig.add_trace( | |
| go.Bar( | |
| x=vector_data["store"], | |
| y=vector_data["indexing_time"], | |
| name="Indexing Time", | |
| marker_color="lightcoral", | |
| ), | |
| row=1, | |
| col=1, | |
| ) | |
| fig.add_trace( | |
| go.Bar( | |
| x=vector_data["store"], | |
| y=vector_data["search_time"], | |
| name="Search Time", | |
| marker_color="lightblue", | |
| ), | |
| row=1, | |
| col=2, | |
| ) | |
| fig.update_layout(height=400, showlegend=False) | |
| return fig | |
| def _create_memory_systems_chart(self): | |
| """ایجاد نمودار سیستمهای حافظه""" | |
| memory_data = self.data_manager.get_memory_system_data() | |
| fig = go.Figure() | |
| fig.add_trace( | |
| go.Bar( | |
| x=memory_data["type"], | |
| y=memory_data["response_time"], | |
| name="Response Time", | |
| marker_color="lightgreen", | |
| ) | |
| ) | |
| fig.update_layout( | |
| title="Memory Systems Performance", | |
| xaxis_title="Memory Type", | |
| yaxis_title="Response Time (seconds)", | |
| height=400, | |
| ) | |
| return fig | |
| def _create_memory_efficiency_chart(self): | |
| """ایجاد نمودار کارایی حافظه""" | |
| memory_data = self.data_manager.get_memory_system_data() | |
| fig = go.Figure() | |
| fig.add_trace( | |
| go.Scatter( | |
| x=memory_data["coherence"], | |
| y=memory_data["memory_efficiency"], | |
| mode="markers+text", | |
| text=memory_data["type"], | |
| textposition="top center", | |
| marker=dict(size=15, color="blue"), | |
| ) | |
| ) | |
| fig.update_layout( | |
| title="Memory Efficiency vs Coherence", | |
| xaxis_title="Coherence Score", | |
| yaxis_title="Memory Efficiency", | |
| height=400, | |
| ) | |
| return fig | |
| def _create_time_series_chart(self): | |
| """ایجاد نمودار سری زمانی""" | |
| time_data = self.data_manager.get_time_series_data() | |
| fig = make_subplots( | |
| rows=2, | |
| cols=1, | |
| subplot_titles=("Daily Queries", "Average Response Time"), | |
| specs=[[{"secondary_y": False}], [{"secondary_y": False}]], | |
| ) | |
| fig.add_trace( | |
| go.Scatter( | |
| x=time_data["date"], | |
| y=time_data["queries"], | |
| name="Queries", | |
| line=dict(color="blue"), | |
| ), | |
| row=1, | |
| col=1, | |
| ) | |
| fig.add_trace( | |
| go.Scatter( | |
| x=time_data["date"], | |
| y=time_data["avg_response_time"], | |
| name="Response Time", | |
| line=dict(color="red"), | |
| ), | |
| row=2, | |
| col=1, | |
| ) | |
| fig.update_layout(height=600, showlegend=False) | |
| return fig | |
| def _create_performance_metrics_chart(self): | |
| """ایجاد نمودار معیارهای عملکرد""" | |
| time_data = self.data_manager.get_time_series_data() | |
| fig = make_subplots( | |
| rows=1, | |
| cols=2, | |
| subplot_titles=("Success Rate", "Memory Usage"), | |
| specs=[[{"secondary_y": False}], [{"secondary_y": False}]], | |
| ) | |
| fig.add_trace( | |
| go.Scatter( | |
| x=time_data["date"], | |
| y=time_data["success_rate"], | |
| name="Success Rate", | |
| line=dict(color="green"), | |
| ), | |
| row=1, | |
| col=1, | |
| ) | |
| fig.add_trace( | |
| go.Scatter( | |
| x=time_data["date"], | |
| y=time_data["memory_usage"], | |
| name="Memory Usage", | |
| line=dict(color="orange"), | |
| ), | |
| row=1, | |
| col=2, | |
| ) | |
| fig.update_layout(height=400, showlegend=False) | |
| return fig | |
| def run(self): | |
| """اجرای داشبورد""" | |
| logger.info(f"Starting dashboard on {self.config.host}:{self.config.port}") | |
| self.app.run_server( | |
| host=self.config.host, port=self.config.port, debug=self.config.debug | |
| ) | |
| def run_interactive_dashboard_demo(): | |
| """اجرای دموی داشبورد تعاملی""" | |
| print("🎛️ Interactive Dashboard Demo") | |
| print("=" * 60) | |
| print("این دمو شامل داشبورد تعاملی برای سیستمهای RAG و حافظه است") | |
| print() | |
| # تنظیمات | |
| config = DashboardConfig( | |
| gemini_api_key=os.getenv("GOOGLE_API_KEY", ""), | |
| port=8050, | |
| host="127.0.0.1", | |
| debug=True, | |
| ) | |
| if not config.gemini_api_key: | |
| print("⚠️ خطا: GOOGLE_API_KEY تنظیم نشده است") | |
| print("لطفاً کلید API خود را تنظیم کنید:") | |
| print("export GOOGLE_API_KEY='your_api_key_here'") | |
| return | |
| try: | |
| # ایجاد داشبورد | |
| print("🔧 Initializing Interactive Dashboard...") | |
| dashboard = InteractiveDashboard(config) | |
| print(f"🚀 Dashboard starting on http://{config.host}:{config.port}") | |
| print("📊 Features available:") | |
| print(" • 📊 نمای کلی سیستم") | |
| print(" • 🗄️ مقایسه Vector Stores") | |
| print(" • 🧠 تحلیل سیستمهای حافظه") | |
| print(" • 🤖 RAG تعاملی") | |
| print(" • 📈 تحلیل عملکرد") | |
| print() | |
| print("💡 برای توقف داشبورد Ctrl+C را فشار دهید") | |
| # اجرای داشبورد | |
| dashboard.run() | |
| except KeyboardInterrupt: | |
| print("\n⏹️ Dashboard stopped by user") | |
| except Exception as e: | |
| print(f"❌ Dashboard failed: {e}") | |
| logger.error(f"Dashboard failed: {e}") | |
| if __name__ == "__main__": | |
| # اجرای دمو | |
| run_interactive_dashboard_demo() | |
Xet Storage Details
- Size:
- 31.3 kB
- Xet hash:
- d0e18271d101203ee7f6c4f4009a66ada4b11ebb30ffdfe5f71bd59d1d6e38ec
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.