kizabgd123 commited on
Commit
e9ecc21
·
verified ·
1 Parent(s): 94bebf8

Upload components/KnowledgeBase.jsx with huggingface_hub

Browse files
Files changed (1) hide show
  1. components/KnowledgeBase.jsx +114 -0
components/KnowledgeBase.jsx ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { useEffect, useState } from 'react';
2
+ import { Card, CardContent, CardHeader, CardTitle } from './ui/Card';
3
+ import { Button } from './ui/Button';
4
+ import { Filter, Download } from 'lucide-react';
5
+
6
+ export default function KnowledgeBase() {
7
+ const [techniques, setTechniques] = useState([]);
8
+ const [competition, setCompetition] = useState('');
9
+ const [loading, setLoading] = useState(false);
10
+
11
+ const fetchTechniques = async () => {
12
+ setLoading(true);
13
+ try {
14
+ const response = await fetch(`/api/database/techniques${competition ? `?competition=${competition}` : ''}`);
15
+ const data = await response.json();
16
+ setTechniques(data);
17
+ } catch (error) {
18
+ console.error('Failed to fetch techniques:', error);
19
+ } finally {
20
+ setLoading(false);
21
+ }
22
+ };
23
+
24
+ const generateConfig = async () => {
25
+ try {
26
+ const response = await fetch('/api/config/generate', {
27
+ method: 'POST',
28
+ headers: { 'Content-Type': 'application/json' },
29
+ body: JSON.stringify({ competition, minConfidence: 0.8 }),
30
+ });
31
+
32
+ const blob = await response.blob();
33
+ const url = window.URL.createObjectURL(blob);
34
+ const a = document.createElement('a');
35
+ a.href = url;
36
+ a.download = 'harvested_config.yaml';
37
+ a.click();
38
+ } catch (error) {
39
+ console.error('Failed to generate config:', error);
40
+ }
41
+ };
42
+
43
+ useEffect(() => {
44
+ fetchTechniques();
45
+ }, []);
46
+
47
+ return (
48
+ <div className="space-y-6">
49
+ <h2 className="text-3xl font-bold text-gray-800">Knowledge Base</h2>
50
+
51
+ <Card>
52
+ <CardHeader>
53
+ <CardTitle>Extracted Techniques</CardTitle>
54
+ </CardHeader>
55
+ <CardContent>
56
+ <div className="flex gap-4 mb-6">
57
+ <input
58
+ type="text"
59
+ placeholder="Filter by competition"
60
+ value={competition}
61
+ onChange={(e) => setCompetition(e.target.value)}
62
+ className="input-field flex-1"
63
+ />
64
+ <Button onClick={fetchTechniques}>
65
+ <Filter className="w-4 h-4 mr-2" />
66
+ Filter
67
+ </Button>
68
+ <Button onClick={generateConfig} variant="secondary">
69
+ <Download className="w-4 h-4 mr-2" />
70
+ Export Config
71
+ </Button>
72
+ </div>
73
+
74
+ {loading ? (
75
+ <div className="text-center py-8">Loading...</div>
76
+ ) : (
77
+ <div className="overflow-x-auto">
78
+ <table className="w-full">
79
+ <thead>
80
+ <tr className="border-b">
81
+ <th className="text-left py-2">Parameter</th>
82
+ <th className="text-left py-2">Value</th>
83
+ <th className="text-left py-2">Confidence</th>
84
+ <th className="text-left py-2">Source</th>
85
+ </tr>
86
+ </thead>
87
+ <tbody>
88
+ {techniques.map((technique) => (
89
+ <tr key={technique.id} className="border-b">
90
+ <td className="py-2 font-mono">{technique.name}</td>
91
+ <td className="py-2">{technique.value}</td>
92
+ <td className="py-2">
93
+ <div className="progress-container">
94
+ <div
95
+ className="progress-bar"
96
+ style={{ width: `${technique.confidence * 100}%` }}
97
+ />
98
+ </div>
99
+ <span className="text-sm">{(technique.confidence * 100).toFixed(1)}%</span>
100
+ </td>
101
+ <td className="py-2 text-sm text-gray-600">
102
+ {technique.rich_context ? 'AST' : 'Regex'}
103
+ </td>
104
+ </tr>
105
+ ))}
106
+ </tbody>
107
+ </table>
108
+ </div>
109
+ )}
110
+ </CardContent>
111
+ </Card>
112
+ </div>
113
+ );
114
+ }