-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathuCard.pas
391 lines (351 loc) · 10.9 KB
/
uCard.pas
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
unit uCard;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls,
FMX.Objects, FMX.Layouts, FireDAC.Stan.Intf, FireDAC.Stan.Option,
FireDAC.Stan.Param, FireDAC.Stan.Error, FireDAC.DatS, FireDAC.Phys.Intf,
FireDAC.DApt.Intf, Data.DB, FireDAC.Comp.DataSet, FireDAC.Comp.Client,
FMX.Controls.Presentation, Data.Bind.EngExt, Fmx.Bind.DBEngExt, System.Rtti,
System.Bindings.Outputs, Fmx.Bind.Editors, Data.Bind.Components,
Data.Bind.DBScope, FMX.ImgList, REST.Types, REST.Client,
REST.Response.Adapter, Data.Bind.ObjectScope, System.Net.URLClient,
System.Net.HttpClient, System.Net.HttpClientComponent, FMX.Platform, FMX.Menus;
type
TCardFrame = class(TFrame)
Layout1: TLayout;
FeedImage: TImage;
Layout2: TLayout;
MenuButton: TButton;
ProfileCircle: TCircle;
NameLabel: TLabel;
Layout3: TLayout;
DownloadButton: TButton;
LoveButton: TButton;
CommentButton: TButton;
GoButton: TButton;
DescLabel: TLabel;
FollowButton: TButton;
TimeLabel: TLabel;
DataMT: TFDMemTable;
BindSourceDB1: TBindSourceDB;
BindingsList1: TBindingsList;
LinkPropertyToFieldFillBitmapBitmap: TLinkPropertyToField;
LinkPropertyToFieldText: TLinkPropertyToField;
LinkPropertyToFieldText4: TLinkPropertyToField;
LinkPropertyToFieldText5: TLinkPropertyToField;
LinkPropertyToFieldBitmap: TLinkPropertyToField;
Glyph1: TGlyph;
Glyph2: TGlyph;
Glyph3: TGlyph;
Timer1: TTimer;
RESTRequest2: TRESTRequest;
FDMemTable2: TFDMemTable;
RESTResponseDataSetAdapter2: TRESTResponseDataSetAdapter;
RESTResponse2: TRESTResponse;
RESTClient2: TRESTClient;
NetHTTPClient1: TNetHTTPClient;
ProgressBar: TProgressBar;
Layout4: TLayout;
Line1: TLine;
Timer2: TTimer;
EditPromptButton: TButton;
CopyPromptButton: TButton;
CopyImageButton: TButton;
UpscaleButton: TButton;
UpscaleMenu: TPopupMenu;
CodeFormerMI: TMenuItem;
RealESRGANMI: TMenuItem;
Swin2SRMI: TMenuItem;
GFPGANMI: TMenuItem;
SwinirMI: TMenuItem;
RundallesrMI: TMenuItem;
EsrganMI: TMenuItem;
CopyBitmapButton: TButton;
UtilsMenu: TPopupMenu;
DeleteMI: TMenuItem;
SendImg2ImgButton: TButton;
procedure FollowButtonClick(Sender: TObject);
procedure LoveButtonClick(Sender: TObject);
procedure CommentButtonClick(Sender: TObject);
procedure GoButtonClick(Sender: TObject);
procedure DownloadButtonClick(Sender: TObject);
procedure CommentsLabelClick(Sender: TObject);
procedure ProfileCircleClick(Sender: TObject);
procedure FeedImageDblClick(Sender: TObject);
procedure FrameResize(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Timer2Timer(Sender: TObject);
procedure EditPromptButtonClick(Sender: TObject);
procedure CopyPromptButtonClick(Sender: TObject);
procedure CopyImageButtonClick(Sender: TObject);
procedure CodeFormerMIClick(Sender: TObject);
procedure RealESRGANMIClick(Sender: TObject);
procedure Swin2SRMIClick(Sender: TObject);
procedure GFPGANMIClick(Sender: TObject);
procedure UpscaleButtonClick(Sender: TObject);
procedure SwinirMIClick(Sender: TObject);
procedure RundallesrMIClick(Sender: TObject);
procedure EsrganMIClick(Sender: TObject);
procedure CopyBitmapButtonClick(Sender: TObject);
procedure DeleteMIClick(Sender: TObject);
procedure SendImg2ImgButtonClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
FMainFeedMT: TFDMemTable;
procedure UpscaleImage(AName: string; AVersion: string);
end;
implementation
{$R *.fmx}
uses
Unit1, System.Threading, System.DateUtils, IdHashMessageDigest, System.IOUtils;
function SaveControl(AControl: TControl): String;
var
LMS: TMemoryStream;
LSS: TStringStream;
LName: string;
begin
LName := AControl.Name;
AControl.Name := '';
try
LMS := TMemoryStream.Create;
try
LMS.WriteComponent(AControl);
LMS.Position := 0;
LSS := TStringStream.Create;
try
ObjectBinaryToText(LMS, LSS);
Result := LSS.DataString;
finally
LSS.Free;
end;
finally
LMS.Free;
end;
finally
AControl.Name := LName;
end;
end;
function MD5(const AString: String): String;
var
LHash: TIdHashMessageDigest5;
begin
LHash := TIdHashMessageDigest5.Create;
try
Result := LHash.HashStringAsHex(AString);
finally
LHash.Free;
end;
end;
procedure TCardFrame.DeleteMIClick(Sender: TObject);
begin
MainForm.DeleteCard(Self);
end;
procedure TCardFrame.DownloadButtonClick(Sender: TObject);
begin
// Download
MainForm.SaveDialog.FileName := DescLabel.Text + '.png';
if MainForm.SaveDialog.Execute then
begin
FeedImage.Bitmap.SaveToFile(MainForm.SaveDialog.FileName);
end;
end;
procedure TCardFrame.EditPromptButtonClick(Sender: TObject);
begin
MainForm.PromptMemo.Lines.Text := DescLabel.Text;
end;
procedure TCardFrame.EsrganMIClick(Sender: TObject);
begin
UpscaleImage(TMenuItem(Sender).Text, 'c263265e04b16fda1046d1828997fc27b46610647a3348df1c72fbffbdbac912');
end;
procedure TCardFrame.UpscaleButtonClick(Sender: TObject);
begin
CodeFormerMIClick(CodeFormerMI);
end;
procedure TCardFrame.UpscaleImage(AName: string; AVersion: string);
begin
var MS := TMemoryStream.Create;
try
FeedImage.Bitmap.SaveToStream(MS);
MainForm.PredictionFromImageStream(AVersion,NameLabel.Text + ' - ' + AName,DescLabel.Text,MS);
finally
MS.Free;
end;
end;
procedure TCardFrame.CodeFormerMIClick(Sender: TObject);
begin
UpscaleImage(TMenuItem(Sender).Text, '7de2ea26c616d5bf2245ad0d5e24f0ff9a6204578a5c876db53142edd9d2cd56');
end;
procedure TCardFrame.CommentButtonClick(Sender: TObject);
begin
// Comment
end;
procedure TCardFrame.CommentsLabelClick(Sender: TObject);
begin
// View Comments
end;
procedure TCardFrame.CopyBitmapButtonClick(Sender: TObject);
var
clp: IFMXClipboardService;
begin
if TPlatformServices.Current.SupportsPlatformService(IFMXClipboardService) then
begin
clp := IFMXClipboardService(TPlatformServices.Current.GetPlatformService(IFMXClipboardService));
clp.SetClipboard(FeedImage.Bitmap);
end;
end;
procedure TCardFrame.CopyImageButtonClick(Sender: TObject);
var
clp: IFMXClipboardService;
begin
if TPlatformServices.Current.SupportsPlatformService(IFMXClipboardService) then
begin
clp := IFMXClipboardService(TPlatformServices.Current.GetPlatformService(IFMXClipboardService));
clp.SetClipboard(SaveControl(FeedImage));
end;
end;
procedure TCardFrame.CopyPromptButtonClick(Sender: TObject);
var
clp: IFMXClipboardService;
begin
if TPlatformServices.Current.SupportsPlatformService(IFMXClipboardService) then
begin
clp := IFMXClipboardService(TPlatformServices.Current.GetPlatformService(IFMXClipboardService));
clp.SetClipboard(DescLabel.Text);
end;
end;
procedure TCardFrame.FeedImageDblClick(Sender: TObject);
begin
// Double Tap Like
LoveButtonClick(Sender);
end;
procedure TCardFrame.FollowButtonClick(Sender: TObject);
begin
// Follow
end;
procedure TCardFrame.FrameResize(Sender: TObject);
begin
FeedImage.Width := Self.Width;
end;
procedure TCardFrame.GFPGANMIClick(Sender: TObject);
begin
UpscaleImage(TMenuItem(Sender).Text, '9283608cc6b7be6b65a8e44983db012355fde4132009bf99d976b2f0896856a3');
end;
procedure TCardFrame.GoButtonClick(Sender: TObject);
begin
// Go
end;
procedure TCardFrame.LoveButtonClick(Sender: TObject);
begin
// Like
end;
procedure TCardFrame.ProfileCircleClick(Sender: TObject);
begin
// View Profile
end;
procedure TCardFrame.RealESRGANMIClick(Sender: TObject);
begin
UpscaleImage(TMenuItem(Sender).Text, '42fed1c4974146d4d2414e2be2c5277c7fcf05fcc3a73abf41610695738c1d7b');
end;
procedure TCardFrame.RundallesrMIClick(Sender: TObject);
begin
UpscaleImage(TMenuItem(Sender).Text, '32fdb2231d00a10d33754cc2ba794a2dfec94216579770785849ce6f149dbc69');
end;
procedure TCardFrame.SendImg2ImgButtonClick(Sender: TObject);
begin
var LFilename := ExtractFilePath(ParamStr(0)) + 'img2img.png';
FeedImage.Bitmap.SaveToFile(LFilename);
MainForm.ImageEdit.Text := LFilename;
end;
procedure TCardFrame.Swin2SRMIClick(Sender: TObject);
begin
UpscaleImage(TMenuItem(Sender).Text, 'a01b0512004918ca55d02e554914a9eca63909fa83a29ff0f115c78a7045574f');
end;
procedure TCardFrame.SwinirMIClick(Sender: TObject);
begin
UpscaleImage(TMenuItem(Sender).Text, '660d922d33153019e8c263a3bba265de882e7f4f70396546b6c9c8f9d47a021a');
end;
procedure TCardFrame.Timer1Timer(Sender: TObject);
begin
Timer1.Enabled := False;
RESTRequest2.Params[0].Value := 'Token ' + MainForm.APIKeyEdit.Text;
RESTRequest2.Resource := Self.Hint;
RESTRequest2.Execute;
var LStatus := FDMemTable2.FieldByName('status').AsWideString;
if LStatus='succeeded' then
begin
var LOutput := FDMemTable2.FieldByName('output').AsWideString.Replace('["','').Replace('"]','').Replace('\/','/');
if LOutput<>'' then
begin
//DataMT.Edit;
//DataMT.FieldByName('Description').AsString := LOutput.Replace('["','').Replace('"]','').Replace('\/','/');
//DataMT.Post;
TTask.Run(procedure var LMS: TMemoryStream; begin
LMS := TMemoryStream.Create;
var HTTPClient := TNetHTTPClient.Create(Self);
try
HTTPClient.Get(LOutput,LMS);
TThread.Synchronize(nil,procedure begin
var LFileName := TPath.Combine(ExtractFilePath(ParamStr(0)),MD5(DataMT.FieldByName('Name').AsString + IntToStr(DateTimeToUnix(Now))) + '.png');
LMS.SaveToFile(LFileName);
DataMT.Edit;
TBlobField(DataMT.FieldByName('Image')).LoadFromStream(LMS);
DataMT.Post;
FMainFeedMT.Append;
FMainFeedMT.CopyRecord(DataMT);
FMainFeedMT.Post;
end);
finally
LMS.Free;
HTTPClient.Free;
TThread.Synchronize(nil,procedure begin
ProgressBar.Visible := False;
//StatusLabel.Text := 'Status: ' + LStatus;
end);
end;
end);
end
else
begin
DataMT.Edit;
DataMT.FieldByName('Description').AsString := 'failed';
DataMT.Post;
ProgressBar.Visible := False;
end;
Timer1.Enabled := False;
end
else
if LStatus='failed' then
begin
DataMT.Edit;
DataMT.FieldByName('Description').AsString := 'failed';
DataMT.Post;
ProgressBar.Visible := False;
Timer1.Enabled := False;
end
else
begin
if ProgressBar.Value=ProgressBar.Max then
ProgressBar.Value := ProgressBar.Min
else
ProgressBar.Value := ProgressBar.Value+5;
Timer1.Enabled := True;
end;
end;
procedure TCardFrame.Timer2Timer(Sender: TObject);
begin
if ProgressBar.Visible = False then
begin
Timer2.Enabled := False;
end
else
begin
if ProgressBar.Value=ProgressBar.Max then
ProgressBar.Value := ProgressBar.Min
else
ProgressBar.Value := ProgressBar.Value+5;
end;
end;
end.