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 (
{JSON.stringify(stats, null, 2)}