00Boobs00 commited on
Commit
7282036
·
verified ·
1 Parent(s): 2c4ce17

Upload components/SecureProcessor.jsx with huggingface_hub

Browse files
Files changed (1) hide show
  1. components/SecureProcessor.jsx +182 -0
components/SecureProcessor.jsx ADDED
@@ -0,0 +1,182 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { useState } from 'react'
2
+ import { Lock, Unlock, FileText, Image, Music, Video, Loader2 } from 'lucide-react'
3
+
4
+ const fileIcons = {
5
+ text: FileText,
6
+ image: Image,
7
+ audio: Music,
8
+ video: Video
9
+ }
10
+
11
+ export default function SecureProcessor({ selectedAgent }) {
12
+ const [inputData, setInputData] = useState('')
13
+ const [file, setFile] = useState(null)
14
+ const [processing, setProcessing] = useState(false)
15
+ const [result, setResult] = useState(null)
16
+ const [operation, setOperation] = useState('analyze')
17
+
18
+ const handleProcess = async () => {
19
+ if (!selectedAgent || (!inputData && !file)) {
20
+ alert('Please select an agent and provide input data')
21
+ return
22
+ }
23
+
24
+ setProcessing(true)
25
+ try {
26
+ const formData = new FormData()
27
+ const data = file || { content: inputData, timestamp: new Date().toISOString() }
28
+
29
+ const response = await fetch('/api/secure-process', {
30
+ method: 'POST',
31
+ headers: {
32
+ 'Content-Type': 'application/json',
33
+ },
34
+ body: JSON.stringify({
35
+ data,
36
+ operation,
37
+ agentId: selectedAgent.id
38
+ })
39
+ })
40
+
41
+ const result = await response.json()
42
+ if (result.success) {
43
+ setResult(result)
44
+ } else {
45
+ throw new Error(result.message)
46
+ }
47
+ } catch (error) {
48
+ console.error('Processing failed:', error)
49
+ alert('Secure processing failed. Check console for details.')
50
+ } finally {
51
+ setProcessing(false)
52
+ }
53
+ }
54
+
55
+ const handleFileUpload = (e) => {
56
+ const uploadedFile = e.target.files[0]
57
+ if (uploadedFile) {
58
+ setFile({
59
+ name: uploadedFile.name,
60
+ type: uploadedFile.type,
61
+ size: uploadedFile.size,
62
+ lastModified: new Date(uploadedFile.lastModified).toISOString()
63
+ })
64
+ }
65
+ }
66
+
67
+ const Icon = fileIcons[selectedAgent?.type?.split(' ')[0].toLowerCase()] || Lock
68
+
69
+ return (
70
+ <div className="card">
71
+ <h2 className="text-2xl font-bold mb-6 flex items-center">
72
+ <Lock className="mr-2 h-6 w-6 text-primary-500" />
73
+ Secure Processing
74
+ </h2>
75
+
76
+ {selectedAgent && (
77
+ <div className="mb-6 p-4 bg-primary-50 dark:bg-primary-900/20 rounded-lg">
78
+ <p className="text-sm text-primary-700 dark:text-primary-300">
79
+ Selected Agent: <span className="font-semibold">{selectedAgent.name}</span>
80
+ </p>
81
+ </div>
82
+ )}
83
+
84
+ <div className="space-y-6">
85
+ <div>
86
+ <label className="block text-sm font-medium mb-2">Operation Type</label>
87
+ <select
88
+ value={operation}
89
+ onChange={(e) => setOperation(e.target.value)}
90
+ className="input-field"
91
+ >
92
+ <option value="analyze">Analyze</option>
93
+ <option value="encrypt">Encrypt</option>
94
+ <option value="sanitize">Sanitize</option>
95
+ <option value="process">Process</option>
96
+ </select>
97
+ </div>
98
+
99
+ <div>
100
+ <label className="block text-sm font-medium mb-2">Input Text</label>
101
+ <textarea
102
+ value={inputData}
103
+ onChange={(e) => setInputData(e.target.value)}
104
+ placeholder="Enter text to process securely..."
105
+ className="input-field min-h-[120px]"
106
+ rows={4}
107
+ />
108
+ </div>
109
+
110
+ <div>
111
+ <label className="block text-sm font-medium mb-2">Or Upload File</label>
112
+ <div className="border-2 border-dashed border-dark-300 dark:border-dark-600 rounded-lg p-6 text-center hover:border-primary-500 transition-colors duration-200">
113
+ <input
114
+ type="file"
115
+ onChange={handleFileUpload}
116
+ className="hidden"
117
+ id="file-upload"
118
+ accept="image/*,audio/*,video/*,text/*,.pdf,.doc,.docx"
119
+ />
120
+ <label htmlFor="file-upload" className="cursor-pointer">
121
+ <Icon className="h-8 w-8 mx-auto mb-2 text-dark-400 dark:text-dark-500" />
122
+ <p className="text-sm text-dark-600 dark:text-dark-400">
123
+ {file ? file.name : 'Click to upload or drag and drop'}
124
+ </p>
125
+ <p className="text-xs text-dark-500 dark:text-dark-500 mt-1">
126
+ Supports images, audio, video, and documents
127
+ </p>
128
+ </label>
129
+ </div>
130
+ </div>
131
+
132
+ <button
133
+ onClick={handleProcess}
134
+ disabled={processing || !selectedAgent}
135
+ className="btn-primary w-full flex items-center justify-center space-x-2 disabled:opacity-50 disabled:cursor-not-allowed"
136
+ >
137
+ {processing ? (
138
+ <>
139
+ <Loader2 className="h-4 w-4 animate-spin" />
140
+ <span>Processing...</span>
141
+ </>
142
+ ) : (
143
+ <>
144
+ <Lock className="h-4 w-4" />
145
+ <span>Process Securely</span>
146
+ </>
147
+ )}
148
+ </button>
149
+
150
+ {result && (
151
+ <div className="mt-6 p-4 bg-dark-50 dark:bg-dark-800 rounded-lg border border-dark-200 dark:border-dark-700">
152
+ <h3 className="font-semibold mb-3 flex items-center">
153
+ <Unlock className="h-4 w-4 mr-2 text-green-500" />
154
+ Processing Result
155
+ </h3>
156
+ <div className="space-y-2 text-sm">
157
+ <div className="flex justify-between">
158
+ <span className="text-dark-600 dark:text-dark-400">Status:</span>
159
+ <span className="font-medium text-green-600 dark:text-green-400">Success</span>
160
+ </div>
161
+ <div className="flex justify-between">
162
+ <span className="text-dark-600 dark:text-dark-400">Security Hash:</span>
163
+ <span className="font-mono text-xs">{result.security.hash.slice(0, 16)}...</span>
164
+ </div>
165
+ <div className="flex justify-between">
166
+ <span className="text-dark-600 dark:text-dark-400">Encryption:</span>
167
+ <span className="font-medium">{result.security.encryption}</span>
168
+ </div>
169
+ {result.data.analysis && (
170
+ <div className="mt-3 p-3 bg-white dark:bg-dark-900 rounded border border-dark-200 dark:border-dark-700">
171
+ <p className="font-medium mb-1">Analysis:</p>
172
+ <p className="text-xs">Sentiment: {result.data.analysis.sentiment}</p>
173
+ <p className="text-xs">Confidence: {result.data.analysis.confidence}%</p>
174
+ </div>
175
+ )}
176
+ </div>
177
+ </div>
178
+ )}
179
+ </div>
180
+ </div>
181
+ )
182
+ }