Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
Avoid packaging model with app - fixing build process
Prompt user with electron file dialog for model path
  • Loading branch information
grctest committed Oct 26, 2024
1 parent 4458b6a commit f1e0c40
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 42 deletions.
Binary file modified app/img/notification.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/img/taskbar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/img/tray.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@
},
"build": {
"appId": "ElectronBitnet",
"productName": "Electron Bitnet",
"productName": "ElectronBitnet",
"artifactName": "ElectronBitnet.${ext}",
"files": [
"app/**/*",
"bin/**/*",
"models/*",
"node_modules/**/*",
"package.json"
],
Expand Down
12 changes: 10 additions & 2 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import fs from 'fs';
import url from "url";
import express from "express";

import { app, BrowserWindow, Menu, Tray, ipcMain, screen, shell } from "electron";
import { app, BrowserWindow, Menu, Tray, ipcMain, shell, dialog } from "electron";

import { initApplicationMenu } from "./lib/applicationMenu.js";

Expand All @@ -23,7 +23,7 @@ function runInference(args) {

const command = [
`"${mainPath}"`,
'-m', path.join('models', args.model),
'-m', args.model,
'-n', args.n_predict,
'-t', args.threads,
'-p', `"${args.prompt}"`,
Expand Down Expand Up @@ -162,6 +162,14 @@ const createWindow = async () => {
signalHandler();
});

ipcMain.handle('openFileDialog', async () => {
const result = await dialog.showOpenDialog({
properties: ['openFile'],
filters: [{ name: 'GGUF Files', extensions: ['gguf'] }]
});
return result.filePaths;
});

tray.on("click", () => {
mainWindow?.setAlwaysOnTop(true);
mainWindow?.show();
Expand Down
59 changes: 23 additions & 36 deletions src/components/Home.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useState, useEffect } from "react";
import { UploadIcon } from "@radix-ui/react-icons";

import {
Card,
Expand All @@ -14,23 +15,11 @@ import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { Textarea } from "@/components/ui/textarea";

import {
Select,
SelectContent,
SelectGroup,
SelectLabel,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";

import ExternalLink from "@/components/ExternalLink.jsx";

export default function Home(properties) {


const [tokenQuantity, setTokenQuantity] = useState(20);
const [model, setModel] = useState("ggml-model-i2_s.gguf");
const [model, setModel] = useState(""); // proven compatible: ggml-model-i2_s.gguf
const [threads, setThreads] = useState(2);
const [ctxSize, setCtxSize] = useState(2048);
const [temperature, setTemperature] = useState(0.8);
Expand All @@ -40,6 +29,13 @@ export default function Home(properties) {
const [runningInference, setRunningInference] = useState(false);
const [aiResponse, setAiResponse] = useState("");

const handleFileSelect = async () => {
const filePaths = await window.electron.openFileDialog();
if (filePaths.length > 0) {
setModel(filePaths[0]);
}
};

useEffect(() => {
if (!window.electron) {
return;
Expand Down Expand Up @@ -86,24 +82,14 @@ export default function Home(properties) {
}}
/>
<Label>Model</Label>
<Select
onValueChange={(model) => {
setModel(model);
}}
value={model}
>
<SelectTrigger>
<SelectValue>{model}</SelectValue>
</SelectTrigger>
<SelectContent>
<SelectGroup>
<SelectLabel>Models</SelectLabel>
<SelectItem value="ggml-model-i2_s.gguf">
ggml-model-i2_s.gguf
</SelectItem>
</SelectGroup>
</SelectContent>
</Select>
<div className="grid grid-cols-4 gap-2">
<div className="col-span-3">
<Input readOnly value={model ? model.split("\\").at(-1) : ""} />
</div>
<Button variant="outline" onClick={handleFileSelect}>
<UploadIcon />
</Button>
</div>
<Label>Threads</Label>
<Input
placeholder={2}
Expand Down Expand Up @@ -152,8 +138,11 @@ export default function Home(properties) {
/>
<div className="grid grid-cols-2 gap-2">
{
!runningInference
? <Button
runningInference || !model
? <Button disabled>
Run Inference
</Button>
: <Button
onClick={() => {
setAiResponse("");
setRunningInference(true);
Expand All @@ -169,9 +158,6 @@ export default function Home(properties) {
>
Run Inference
</Button>
: <Button disabled>
Run Inference
</Button>
}

<Button
Expand All @@ -185,6 +171,7 @@ export default function Home(properties) {

</div>
<div className="col-span-2">
<b>Response</b>
<Textarea readOnly={true} rows={20} className="w-full" value={aiResponse} />
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { ipcRenderer, contextBridge } from "electron";

contextBridge.exposeInMainWorld("electron", {
openURL: async (target) => ipcRenderer.send("openURL", target),
// on aiResponse
onAiResponse: (func) => {
ipcRenderer.on("aiResponse", (event, data) => {
func(data);
Expand All @@ -19,5 +18,6 @@ contextBridge.exposeInMainWorld("electron", {
});
},
runInference: async (args) => ipcRenderer.send("runInference", args),
stopInference: async (args) => ipcRenderer.send("stopInference", args)
stopInference: async (args) => ipcRenderer.send("stopInference", args),
openFileDialog: async () => ipcRenderer.invoke("openFileDialog"),
});

0 comments on commit f1e0c40

Please sign in to comment.