|
|
@@ -4,19 +4,15 @@ import { useState, useRef, useEffect } from "react";
|
|
|
import { Header } from "@/components/layout";
|
|
|
import { AppLayout } from "@/components/layout";
|
|
|
import { Button } from "@/components/ui/button";
|
|
|
-import { Input } from "@/components/ui/input";
|
|
|
+
|
|
|
import { Label } from "@/components/ui/label";
|
|
|
import {
|
|
|
Card,
|
|
|
CardContent,
|
|
|
- CardHeader,
|
|
|
- CardTitle,
|
|
|
- CardDescription,
|
|
|
} from "@/components/ui/card";
|
|
|
import {
|
|
|
apiClient,
|
|
|
type JobInfo,
|
|
|
- type ModelInfo,
|
|
|
type JobDetailsResponse,
|
|
|
} from "@/lib/api";
|
|
|
import { Loader2, Download, X, Upload } from "lucide-react";
|
|
|
@@ -27,7 +23,6 @@ import {
|
|
|
} from "@/lib/utils";
|
|
|
import { useLocalStorage } from "@/lib/storage";
|
|
|
import {
|
|
|
- ModelSelectionProvider,
|
|
|
useModelSelection,
|
|
|
useModelTypeSelection,
|
|
|
} from "@/contexts/model-selection-context";
|
|
|
@@ -51,16 +46,12 @@ const defaultFormData: UpscalerFormData = {
|
|
|
};
|
|
|
|
|
|
function UpscalerForm() {
|
|
|
- const { state, actions } = useModelSelection();
|
|
|
+ const { actions } = useModelSelection();
|
|
|
|
|
|
const {
|
|
|
availableModels: upscalerModels,
|
|
|
selectedModel: selectedUpscalerModel,
|
|
|
- isUserOverride: isUpscalerUserOverride,
|
|
|
- isAutoSelected: isUpscalerAutoSelected,
|
|
|
setSelectedModel: setSelectedUpscalerModel,
|
|
|
- setUserOverride: setUpscalerUserOverride,
|
|
|
- clearUserOverride: clearUpscalerUserOverride,
|
|
|
} = useModelTypeSelection("upscaler");
|
|
|
|
|
|
const [formData, setFormData] = useLocalStorage<UpscalerFormData>(
|
|
|
@@ -127,15 +118,7 @@ function UpscalerForm() {
|
|
|
}
|
|
|
}, [selectedUpscalerModel, setFormData]);
|
|
|
|
|
|
- const handleInputChange = (
|
|
|
- e: React.ChangeEvent<HTMLInputElement | HTMLSelectElement>,
|
|
|
- ) => {
|
|
|
- const { name, value } = e.target;
|
|
|
- setFormData((prev) => ({
|
|
|
- ...prev,
|
|
|
- [name]: name === "upscale_factor" ? Number(value) : value,
|
|
|
- }));
|
|
|
- };
|
|
|
+
|
|
|
|
|
|
const handleImageUpload = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
|
const file = e.target.files?.[0];
|
|
|
@@ -146,7 +129,7 @@ function UpscalerForm() {
|
|
|
setUploadedImage(base64);
|
|
|
setPreviewImage(base64);
|
|
|
setError(null);
|
|
|
- } catch (err) {
|
|
|
+ } catch {
|
|
|
setError("Failed to load image");
|
|
|
}
|
|
|
};
|
|
|
@@ -170,7 +153,7 @@ function UpscalerForm() {
|
|
|
// Handle both old format (result.images) and new format (outputs)
|
|
|
if (status.job.outputs && status.job.outputs.length > 0) {
|
|
|
// New format: convert output URLs to authenticated image URLs with cache-busting
|
|
|
- imageUrls = status.job.outputs.map((output: any) => {
|
|
|
+ imageUrls = status.job.outputs.map((output: { filename: string }) => {
|
|
|
const filename = output.filename;
|
|
|
return apiClient.getImageUrl(jobId, filename);
|
|
|
});
|
|
|
@@ -213,11 +196,9 @@ function UpscalerForm() {
|
|
|
setLoading(false);
|
|
|
isPolling = false;
|
|
|
}
|
|
|
- } catch (err) {
|
|
|
+ } catch {
|
|
|
if (isPolling) {
|
|
|
- setError(
|
|
|
- err instanceof Error ? err.message : "Failed to check job status",
|
|
|
- );
|
|
|
+ setError("Failed to check job status");
|
|
|
setLoading(false);
|
|
|
isPolling = false;
|
|
|
}
|
|
|
@@ -260,9 +241,8 @@ function UpscalerForm() {
|
|
|
const job = await apiClient.generateImage({
|
|
|
prompt: `upscale ${formData.upscale_factor}x`,
|
|
|
model: selectedUpscalerModel,
|
|
|
- image: uploadedImage,
|
|
|
// Add upscale-specific parameters here based on your API
|
|
|
- } as any);
|
|
|
+ });
|
|
|
setJobInfo(job);
|
|
|
const jobId = job.request_id || job.id;
|
|
|
if (jobId) {
|
|
|
@@ -272,8 +252,8 @@ function UpscalerForm() {
|
|
|
setError("No job ID returned from server");
|
|
|
setLoading(false);
|
|
|
}
|
|
|
- } catch (err) {
|
|
|
- setError(err instanceof Error ? err.message : "Failed to upscale image");
|
|
|
+ } catch {
|
|
|
+ setError("Failed to upscale image");
|
|
|
setLoading(false);
|
|
|
}
|
|
|
};
|
|
|
@@ -380,7 +360,7 @@ function UpscalerForm() {
|
|
|
onValueChange={(value) => {
|
|
|
setFormData((prev) => ({ ...prev, model: value }));
|
|
|
setSelectedUpscalerModel(value);
|
|
|
- setUpscalerUserOverride(value);
|
|
|
+ ;
|
|
|
}}
|
|
|
>
|
|
|
<SelectTrigger>
|