File size: 9,030 Bytes
9aefa19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
import { useState } from 'react'

function OptionsPanel({ fileType, options, setOptions }) {
  const [showAdvanced, setShowAdvanced] = useState(false)

  const updateOption = (key, value) => {
    setOptions(prev => ({ ...prev, [key]: value }))
  }

  return (
    <div>
      <h2 className="text-2xl font-semibold mb-4 text-gray-800">Processing Options</h2>

      {/* Model Selection */}
      <div className="mb-4">
        <label className="block text-sm font-medium text-gray-700 mb-2">
          Model
        </label>
        <select
          value={options.model}
          onChange={(e) => updateOption('model', e.target.value)}
          className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500"
        >
          <option value="u2net">U2Net (Default)</option>
          <option value="u2netp">U2NetP (Lightweight)</option>
          <option value="u2net_human_seg">U2Net Human Segmentation</option>
        </select>
      </div>

      {/* Alpha Matting (Image only) */}
      {fileType === 'image' && (
        <>
          <div className="mb-4">
            <label className="flex items-center space-x-2">
              <input
                type="checkbox"
                checked={options.alphaMatting}
                onChange={(e) => updateOption('alphaMatting', e.target.checked)}
                className="rounded border-gray-300 text-indigo-600 focus:ring-indigo-500"
              />
              <span className="text-sm font-medium text-gray-700">Enable Alpha Matting</span>
            </label>
          </div>

          {options.alphaMatting && (
            <div className="ml-6 mb-4 space-y-3 p-4 bg-gray-50 rounded-lg">
              <div>
                <label className="block text-sm font-medium text-gray-700 mb-1">
                  Foreground Threshold
                </label>
                <input
                  type="number"
                  value={options.alphaMattingForegroundThreshold}
                  onChange={(e) => updateOption('alphaMattingForegroundThreshold', parseInt(e.target.value))}
                  className="w-full px-3 py-2 border border-gray-300 rounded-lg"
                  min="0"
                  max="255"
                />
              </div>
              <div>
                <label className="block text-sm font-medium text-gray-700 mb-1">
                  Background Threshold
                </label>
                <input
                  type="number"
                  value={options.alphaMattingBackgroundThreshold}
                  onChange={(e) => updateOption('alphaMattingBackgroundThreshold', parseInt(e.target.value))}
                  className="w-full px-3 py-2 border border-gray-300 rounded-lg"
                  min="0"
                  max="255"
                />
              </div>
              <div>
                <label className="block text-sm font-medium text-gray-700 mb-1">
                  Erode Structure Size
                </label>
                <input
                  type="number"
                  value={options.alphaMattingErodeStructureSize}
                  onChange={(e) => updateOption('alphaMattingErodeStructureSize', parseInt(e.target.value))}
                  className="w-full px-3 py-2 border border-gray-300 rounded-lg"
                  min="1"
                />
              </div>
              <div>
                <label className="block text-sm font-medium text-gray-700 mb-1">
                  Base Size
                </label>
                <input
                  type="number"
                  value={options.alphaMattingBaseSize}
                  onChange={(e) => updateOption('alphaMattingBaseSize', parseInt(e.target.value))}
                  className="w-full px-3 py-2 border border-gray-300 rounded-lg"
                  min="100"
                />
              </div>
            </div>
          )}
        </>
      )}

      {/* Video Options */}
      {fileType === 'video' && (
        <div className="mb-4 space-y-2">
          <label className="flex items-center space-x-2">
            <input
              type="checkbox"
              checked={options.tv}
              onChange={(e) => updateOption('tv', e.target.checked)}
              className="rounded border-gray-300 text-indigo-600 focus:ring-indigo-500"
            />
            <span className="text-sm font-medium text-gray-700">TV Mode (-tv)</span>
          </label>
          <label className="flex items-center space-x-2">
            <input
              type="checkbox"
              checked={options.mk}
              onChange={(e) => updateOption('mk', e.target.checked)}
              className="rounded border-gray-300 text-indigo-600 focus:ring-indigo-500"
            />
            <span className="text-sm font-medium text-gray-700">Masks Only (-mk)</span>
          </label>
          <label className="flex items-center space-x-2">
            <input
              type="checkbox"
              checked={options.tov}
              onChange={(e) => updateOption('tov', e.target.checked)}
              className="rounded border-gray-300 text-indigo-600 focus:ring-indigo-500"
            />
            <span className="text-sm font-medium text-gray-700">Transparent Output Video (-tov)</span>
          </label>
          <label className="flex items-center space-x-2">
            <input
              type="checkbox"
              checked={options.toi}
              onChange={(e) => updateOption('toi', e.target.checked)}
              className="rounded border-gray-300 text-indigo-600 focus:ring-indigo-500"
            />
            <span className="text-sm font-medium text-gray-700">Transparent Output Images (-toi)</span>
          </label>
          <label className="flex items-center space-x-2">
            <input
              type="checkbox"
              checked={options.gb}
              onChange={(e) => updateOption('gb', e.target.checked)}
              className="rounded border-gray-300 text-indigo-600 focus:ring-indigo-500"
            />
            <span className="text-sm font-medium text-gray-700">Green Background (-gb)</span>
          </label>
          <label className="flex items-center space-x-2">
            <input
              type="checkbox"
              checked={options.wn}
              onChange={(e) => updateOption('wn', e.target.checked)}
              className="rounded border-gray-300 text-indigo-600 focus:ring-indigo-500"
            />
            <span className="text-sm font-medium text-gray-700">White Background (-wn)</span>
          </label>
          <div className="grid grid-cols-2 gap-4">
            <div>
              <label className="block text-sm font-medium text-gray-700 mb-1">
                Frame Rate (-fr)
              </label>
              <input
                type="number"
                value={options.fr || ''}
                onChange={(e) => updateOption('fr', e.target.value ? parseFloat(e.target.value) : null)}
                className="w-full px-3 py-2 border border-gray-300 rounded-lg"
                placeholder="Optional"
                step="0.1"
              />
            </div>
            <div>
              <label className="block text-sm font-medium text-gray-700 mb-1">
                Frame Limit (-fl)
              </label>
              <input
                type="number"
                value={options.fl || ''}
                onChange={(e) => updateOption('fl', e.target.value ? parseFloat(e.target.value) : null)}
                className="w-full px-3 py-2 border border-gray-300 rounded-lg"
                placeholder="Optional"
                step="0.1"
              />
            </div>
          </div>
        </div>
      )}

      {/* Background Options */}
      <div className="mb-4">
        <label className="block text-sm font-medium text-gray-700 mb-2">
          Background Color (Hex, e.g., #FF0000)
        </label>
        <input
          type="text"
          value={options.backgroundColor}
          onChange={(e) => updateOption('backgroundColor', e.target.value)}
          className="w-full px-3 py-2 border border-gray-300 rounded-lg"
          placeholder="#FFFFFF or leave empty for transparent"
        />
      </div>

      <div className="mb-4">
        <label className="block text-sm font-medium text-gray-700 mb-2">
          Background Image (Optional)
        </label>
        <input
          type="file"
          accept="image/*"
          onChange={(e) => {
            const bgFile = e.target.files[0]
            if (bgFile) {
              updateOption('backgroundImage', bgFile)
            }
          }}
          className="w-full px-3 py-2 border border-gray-300 rounded-lg"
        />
        {options.backgroundImage && (
          <p className="mt-2 text-sm text-gray-600">
            Selected: {options.backgroundImage.name}
          </p>
        )}
      </div>
    </div>
  )
}

export default OptionsPanel