import React, { useState, useEffect } from 'react'; import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend } from 'recharts'; import { Upload, RefreshCw, Database, FileText, Settings } from 'lucide-react'; import { Card, CardHeader, CardTitle, CardContent } from '@/components/ui/card'; import { Alert, AlertDescription } from '@/components/ui/alert'; import { Button } from '@/components/ui/button'; const AdminDashboard = () => { // Sample data for learning chart const [learningData, setLearningData] = useState([]); const [isUpdating, setIsUpdating] = useState(false); const [chatHistory, setChatHistory] = useState([]); const [message, setMessage] = useState(''); const [stats, setStats] = useState({}); const [plotData, setPlotData] = useState([]); const handleKnowledgeUpdate = () => { setIsUpdating(true); // Simulate update setTimeout(() => setIsUpdating(false), 2000); }; const handleChatSubmit = async () => { const response = await fetch('http://localhost:7860/api/chat', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ message, history: chatHistory }) }); const data = await response.json(); setChatHistory(data.history); setMessage(''); }; const handleFileUpload = async (file) => { const formData = new FormData(); formData.append('file', file); const response = await fetch('http://localhost:7860/api/upload', { method: 'POST', body: formData }); const data = await response.json(); alert(data.message); }; const handleShowStats = async () => { const response = await fetch('http://localhost:7860/api/stats'); const data = await response.json(); setStats(data.stats); setPlotData(data.plot); }; useEffect(() => { // Fetch initial learning data const fetchLearningData = async () => { const response = await fetch('http://localhost:7860/api/learning_data'); const data = await response.json(); setLearningData(data); }; fetchLearningData(); }, []); return (
{/* Header */}

Admin Dashboard

{/* Statistics Cards */}
{stats.average_response_time || '89%'}
Current Learning Rate
{stats.total_interactions || '1,234'}
Number of Answered Questions
{stats.user_satisfaction || '95%'}
User Satisfaction
{/* Learning Chart */} Learning Rate Trend
{/* Operation Buttons */}
{/* Alerts and Announcements */} Last knowledge base update: Yesterday at 15:30 {/* Chat */}
Chat
{chatHistory.map((msg, index) => (
{msg}
))}
setMessage(e.target.value)} onKeyPress={(e) => e.key === 'Enter' && handleChatSubmit()} />
{/* Upload Documents */}
Upload Documents handleFileUpload(e.target.files[0])} />
{/* Statistics */}
Statistics
{JSON.stringify(stats, null, 2)}
); }; export default AdminDashboard;