Skip to content

Commit

Permalink
Merge pull request ohmplatform#51 from ohmplatform/docker-app
Browse files Browse the repository at this point in the history
Docker app
  • Loading branch information
bhattaraijay05 authored Apr 19, 2023
2 parents b31418b + c55f122 commit 168436e
Show file tree
Hide file tree
Showing 28 changed files with 2,709 additions and 1 deletion.
19 changes: 19 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,25 @@ yarn start
⦻ Make sure you are in the root directory of the project.
```

## Dockerizing the application

To run the docker image, run the following command in your terminal:

```sh
docker pull freedomgpt/freedomgpt
docker run -d -p 8889:8889 freedomgpt/freedomgpt
```

If you want to build the docker image yourself, run the following command in your terminal:

```sh
docker build -t freedomgpt/freedomgpt .

OR

yarn docker
```

## Working Video

https://user-images.githubusercontent.com/54356944/231952507-94ef7335-4238-43ee-8c45-677f6cd48988.mov
Expand Down
1 change: 1 addition & 0 deletions docker-app/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
44 changes: 44 additions & 0 deletions docker-app/dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Use an official Ubuntu as a parent image
FROM ubuntu:latest

# Set the working directory to /app
WORKDIR /app

# Update the package list and install necessary packages
RUN apt-get update && \
apt-get install -y git wget curl build-essential && \
rm -rf /var/lib/apt/lists/*

# clone one git repo
RUN git clone "https://github.com/antimatter15/alpaca.cpp.git"

# cd into alpaca.cpp folder and run make command
RUN cd alpaca.cpp && make && cd ..

RUN wget "https://huggingface.co/sosaka/alpaca-native-4bit-ggml/resolve/main/ggml-alpaca-7b-q4.bin"

# copy the chat file to /app
RUN cp alpaca.cpp/chat .

# remove the alpaca.cpp folder
RUN rm -rf alpaca.cpp

# Copy the package.json and package-lock.json files to the container
COPY package*.json ./

# Install the dependencies and Node.js
RUN curl -sL https://deb.nodesource.com/setup_18.x | bash -
RUN apt-get install -y nodejs
RUN npm install -g [email protected] && npm install && rm -rf /var/lib/apt/lists/*

# Copy the rest of the application files to the container
COPY . .

# Build the Vite app
RUN npm run build

# Expose port 8889 for the Express app
EXPOSE 8889

# Start the Express app
CMD ["npm", "start"]
13 changes: 13 additions & 0 deletions docker-app/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="logo.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>FreedomGPT</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
Binary file added docker-app/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions docker-app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "client",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"preview": "vite preview",
"start": "node server.js"
},
"dependencies": {
"concurrently": "^8.0.1",
"cors": "^2.8.5",
"express": "^4.18.2",
"global": "^4.4.0",
"http": "^0.0.1-security",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"socket.io": "^4.6.1",
"socket.io-client": "^4.6.1",
"uuid": "^9.0.0"
},
"devDependencies": {
"@types/react": "^18.0.28",
"@types/react-dom": "^18.0.11",
"@types/uuid": "^9.0.1",
"@vitejs/plugin-react": "^3.1.0",
"typescript": "^4.9.3",
"vite": "^4.2.0"
}
}
1 change: 1 addition & 0 deletions docker-app/public/vite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
93 changes: 93 additions & 0 deletions docker-app/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { spawn } from "child_process";
import express from "express";
import http from "http";
import path from "path";
import { Server } from "socket.io";

const expressapp = express();
const server = http.createServer(expressapp);
const io = new Server(server, {
cors: {
origin: "*",
methods: ["GET", "POST"],
},
});

const EXPRESSPORT = 8889;

let numClients = 0;

expressapp.use(
"/assets",
express.static(path.join(process.cwd(), "dist/assets"))
);

expressapp.get("*", (req, res) => {
res.sendFile(path.join(process.cwd(), "dist/index.html"));
});

io.on("connection", (socket) => {
if (numClients === 1) {
console.log("Only one client allowed");
socket.disconnect();
return;
}

numClients++;

console.log("Client Connected");
const CHAT_APP_LOCATION = path.join(process.cwd(), "/chat");
const FILEPATH = path.join(process.cwd(), "/ggml-alpaca-7b-q4.bin");

let program = spawn(CHAT_APP_LOCATION, ["-m", FILEPATH]);

socket.on("chatstart", () => {
program = spawn(CHAT_APP_LOCATION, ["-m", FILEPATH]);
});

program.on("error", (err) => {
console.error(err);
});

socket.on("stopResponding", () => {
program.kill();
program = null;
socket.emit("chatend");
});

socket.on("message", (message) => {
program.stdin.write(message + "\n");

let closing = "";
program.stdout.on("data", (data) => {
let output = data.toString("utf8");

if (output.includes(">")) {
closing = closing.concat(">");
}

output = output.replace(">", "");

const response = { result: "success", output: output };
socket.emit("response", response);

if (closing.includes(">>")) {
program.kill();
program = null;
socket.emit("chatend");
}
});
});

socket.on("disconnect", () => {
numClients--;
program.kill();
program = null;
});
});

server.listen(EXPRESSPORT, () => {
console.log(`Server listening on port ${EXPRESSPORT}`);
});

export default expressapp;
15 changes: 15 additions & 0 deletions docker-app/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from "react";
import Main from "./app/screens/Main";
import MessageFetchProvider from "./app/context/MessageFetch";

const App = () => {
return (
<>
<MessageFetchProvider>
<Main />
</MessageFetchProvider>
</>
);
};

export default App;
Binary file added docker-app/src/Roboto-Regular.ttf
Binary file not shown.
104 changes: 104 additions & 0 deletions docker-app/src/app/components/Icons.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
export const thunder = (
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
strokeWidth="1.5"
stroke="currentColor"
aria-hidden="true"
className="h-6 w-6"
height="1.5em"
width="1.5em"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M3.75 13.5l10.5-11.25L12 10.5h8.25L9.75 21.75 12 13.5H3.75z"
></path>
</svg>
);

export const sun = (
<svg
stroke="currentColor"
fill="none"
strokeWidth="1.5"
viewBox="0 0 24 24"
strokeLinecap="round"
strokeLinejoin="round"
className="h-6 w-6"
height="1.5em"
width="1.5em"
xmlns="http://www.w3.org/2000/svg"
>
<circle cx="12" cy="12" r="5"></circle>
<line x1="12" y1="1" x2="12" y2="3"></line>
<line x1="12" y1="21" x2="12" y2="23"></line>
<line x1="4.22" y1="4.22" x2="5.64" y2="5.64"></line>
<line x1="18.36" y1="18.36" x2="19.78" y2="19.78"></line>
<line x1="1" y1="12" x2="3" y2="12"></line>
<line x1="21" y1="12" x2="23" y2="12"></line>
<line x1="4.22" y1="19.78" x2="5.64" y2="18.36"></line>
<line x1="18.36" y1="5.64" x2="19.78" y2="4.22"></line>
</svg>
);

export const alert = (
<svg
stroke="currentColor"
fill="none"
strokeWidth="1.5"
viewBox="0 0 24 24"
strokeLinecap="round"
strokeLinejoin="round"
className="h-6 w-6"
height="1.5em"
width="1.5em"
xmlns="http://www.w3.org/2000/svg"
>
<path d="M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"></path>
<line x1="12" y1="9" x2="12" y2="13"></line>
<line x1="12" y1="17" x2="12.01" y2="17"></line>
</svg>
);

export const send = (
<svg
stroke="currentColor"
fill="none"
strokeWidth="2"
viewBox="0 0 30 30"
strokeLinecap="round"
strokeLinejoin="round"
className="h-4 w-4 mr-1"
height="4em"
width="4em"
xmlns="http://www.w3.org/2000/svg"
>
<line x1="22" y1="2" x2="11" y2="13"></line>
<polygon points="22 2 15 22 11 13 2 9 22 2"></polygon>
</svg>
);

export const boticon = (
<svg
viewBox="0 0 100 200"
xmlns="http://www.w3.org/2000/svg"
stroke="currentColor"
fill="none"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
className="h-4 w-4 mr-1"
height="4em"
width="4em"
>
<path
fill="#77B5FE"
d="M50,0 L100,50 L60,70 L60,110 L100,120 L100,200 L0,200 L0,120 L40,110 L40,70 L0,50 L50,0z"
/>
<path fill="#3F3D56" d="M60,70 L40,70 L40,90 L60,90z" />
<path fill="#C4C4C4" d="M47,40 L53,40 L53,70 L47,70z" />
<circle cx="50" cy="25" r="15" fill="#C4C4C4" />
</svg>
);
Loading

0 comments on commit 168436e

Please sign in to comment.