Skip to content

Commit

Permalink
Merge pull request #19 from LoopMind-AI/user_auth
Browse files Browse the repository at this point in the history
Add local and cloud selections
  • Loading branch information
jinyu-loopmind committed Sep 15, 2023
2 parents fb8a3f4 + 9a47cb0 commit 3f09685
Show file tree
Hide file tree
Showing 27 changed files with 589 additions and 190 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,7 @@ coverage.xml
# Sphinx documentation
docs/_build/

.ipynb_checkpoints/
.ipynb_checkpoints/

# Added by LoopQuest
.env
37 changes: 19 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
# :scroll:Loopquest

A Production Tool for Embodied AI.
[![Downloads](https://static.pepy.tech/badge/loopquest)](https://pepy.tech/project/loopquest)
[![Downloads](https://static.pepy.tech/badge/loopquest/month)](https://pepy.tech/project/loopquest)
[![Downloads](https://static.pepy.tech/badge/loopquest/week)](https://pepy.tech/project/loopquest)

A Production Tool for Embodied AI.
![loopquest frontend](screenshots/loopquest-screenshot.png)

- :video_camera:[Tutorial Video - Updated 9/4/2023](https://capture.dropbox.com/UXKQxGkwel6VRZJQ), [Dataset Demo](https://capture.dropbox.com/AOF5rGxHWyRb9T58)
- :house:[Discord](https://discord.gg/FTnFYeSy9r)

# Major features

- Imitation Learning / Offline Reinforcement Learning Oriented MLOps. Log all the observation, action, reward, rendered images into database with only ONE extra line of code.

```python
Expand All @@ -16,11 +21,12 @@ env = gymnasium.make("MountainCarContinuous-v0", render_mode="rgb_array")
->

```python
from loopquest.gym_wrappers import LoopquestGymWrapper
env = LoopquestGymWrapper(
gymnasium.make("MountainCarContinuous-v0", render_mode="rgb_array"), "my_experiment"
import loopquest
env = loopquest.make_env(
gymnasium.make("MountainCarContinuous-v0", render_mode="rgb_array")
)
```

- Directly trainable data for robotics foundation model. Select and download the (observation, action, reward) data with the dataloader interfaces of the most popular deep learning frameworks (e.g. tensorflow, pytorch, huggingface dataset apis). Check [Dataset Quickstart Example](examples/Dataset%20Quickstart.ipynb) for more details.

```python
Expand Down Expand Up @@ -55,7 +61,9 @@ The data schema will look like
'images': [<PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=600x400 at 0x7F8D33094450>]
}
```

- All the regular MLOps features are included, e.g. data visualization, simulation rendering, experiment management.

# Installation

For stable version, run
Expand All @@ -77,21 +85,15 @@ cd loopquest
pip install -e .
```

# How to run
# Usage

At `loopquest` folder, bring up web-app,

```sh
docker compose up --build
```

Then run quickstart script,
Run [quickstart script](examples/quickstart.py),

```sh
python examples/quickstart.py
```

The command prompt should mention "Check your experiment progress on `http://localhost:5667/experiment/<exp_id>`".
The command prompt will ask you to select local or cloud instance. Pick the instance you want and once the script is up and running. You should see "Check your experiment progress on `http://localhost:5667/experiment/<exp_id>` or `https://open.loopquest.ai/experiment/<exp_id`" (depending on the instance you selected).

**Loopquest Developer Only**: to bring up a development server that reflects your local changes in real time, run

Expand All @@ -103,12 +105,10 @@ bash start_dev_server.sh

```python
import gymnasium
from loopquest.gym_wrappers import LoopquestGymWrapper
import loopquest

experiment_name = "test"
env = LoopquestGymWrapper(
gymnasium.make("MountainCarContinuous-v0", render_mode="rgb_array"),
experiment_name,
env = loopquest.make_env(
gymnasium.make("MountainCarContinuous-v0", render_mode="rgb_array")
)
obs, info = env.reset()
for i in range(100):
Expand All @@ -118,4 +118,5 @@ for i in range(100):
if terminated or truncated:
break
env.close()

```
2 changes: 1 addition & 1 deletion backend/src/apps/experiment/routers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
)


@api_router.post("/", response_model=schema.Experiment)
@api_router.post("", response_model=schema.Experiment)
async def create_experiment(request: Request, experiment: schema.ExperimentCreate):
while True:
try:
Expand Down
5 changes: 4 additions & 1 deletion docker-compose-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ services:
- BACKEND_URL=http://backend:8000
volumes:
- ./frontend:/frontend
- /frontend/node_modules
- ./frontend/package.json:/frontend/package.json
- ./frontend/package-lock.json:/frontend/package-lock.json
- node_modules:/frontend/node_modules
depends_on:
- backend

Expand Down Expand Up @@ -51,3 +53,4 @@ services:
volumes:
db:
media_store:
node_modules:
10 changes: 2 additions & 8 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
services:
frontend:
container_name: loopquest-frontend
image: loopquest-frontend
build:
context: .
dockerfile: Dockerfile.frontend
image: jinyuloopmind/loopquest-frontend:prod
ports:
# FUN FACT: The port 5667 means "LOOP" on the dial pad.
- "5667:3000"
Expand All @@ -15,10 +12,7 @@ services:

backend:
container_name: loopquest-backend
image: loopquest-backend
build:
context: .
dockerfile: Dockerfile.backend
image: jinyuloopmind/loopquest-backend:prod
environment:
# NOTE: This URL is the one exposed by the frontend container.
- APP_URL=http://localhost:5667
Expand Down
11 changes: 11 additions & 0 deletions docker_release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
TAG=prod
# TAG=staging

docker build -t loopquest-frontend:$TAG -f Dockerfile.frontend .
docker tag loopquest-frontend:$TAG jinyuloopmind/loopquest-frontend:$TAG
docker push jinyuloopmind/loopquest-frontend:$TAG

docker build -t loopquest-backend:$TAG -f Dockerfile.backend .
docker tag loopquest-backend:$TAG jinyuloopmind/loopquest-backend:$TAG
docker push jinyuloopmind/loopquest-backend:$TAG
8 changes: 3 additions & 5 deletions examples/quickstart.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import gymnasium
from loopquest.gym_wrappers import LoopquestGymWrapper
import loopquest

experiment_name = "test"
env = LoopquestGymWrapper(
gymnasium.make("MountainCarContinuous-v0", render_mode="rgb_array"),
experiment_name,
env = loopquest.make_env(
gymnasium.make("MountainCarContinuous-v0", render_mode="rgb_array")
)
obs, info = env.reset()
for i in range(100):
Expand Down
7 changes: 2 additions & 5 deletions examples/run_simglucose.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import gymnasium
from loopquest.gym_wrappers import LoopquestGymWrapper
import loopquest
from gymnasium.envs.registration import register

register(
Expand All @@ -9,10 +9,7 @@
)

experiment_name = "a test"
env = LoopquestGymWrapper(
gymnasium.make("simglucose/adolescent2-v0"),
experiment_name,
)
env = loopquest.make_env(gymnasium.make("simglucose/adolescent2-v0"))
obs, info = env.reset()
for i in range(100):
action = env.action_space.sample()
Expand Down
44 changes: 0 additions & 44 deletions frontend/lib/gtag.tsx

This file was deleted.

1 change: 0 additions & 1 deletion frontend/src/components/line_chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ export default function LineChart({ line_data }: { line_data: VariableData }) {
return {
label: data.name,
data: data.value,
fill: true,
tension: 0.1,
pointRadius: 0,
};
Expand Down
4 changes: 0 additions & 4 deletions frontend/src/components/navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ export default function Navbar() {
<li>
<Link href="/datasets">Datasets</Link>
</li>
</ul>
</div>
<div className="navbar-end">
<ul className="menu menu-horizontal px-1 text-lg">
<li>
<Link href="/about">About</Link>
</li>
Expand Down
15 changes: 0 additions & 15 deletions frontend/src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,10 @@ import Layout from "@/components/layout";
import type { AppProps } from "next/app";
import { config } from "@fortawesome/fontawesome-svg-core";
import "@fortawesome/fontawesome-svg-core/styles.css";
import { useRouter } from "next/router";
import { useEffect } from "react";
import * as gtag from "../../lib/gtag";

config.autoAddCss = false;
const isProduction = process.env.NODE_ENV === "production";

const App = ({ Component, pageProps }: AppProps): JSX.Element => {
const router = useRouter();
useEffect(() => {
const handleRouteChange = (url: URL) => {
/* invoke analytics function only for production */
if (isProduction) gtag.pageview(url);
};
router.events.on("routeChangeComplete", handleRouteChange);
return () => {
router.events.off("routeChangeComplete", handleRouteChange);
};
}, [router.events]);
return (
<Layout>
<Component {...pageProps} />
Expand Down
29 changes: 1 addition & 28 deletions frontend/src/pages/_document.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,9 @@
import { Html, Head, Main, NextScript } from "next/document";

import { GA_TRACKING_ID } from "../../lib/gtag";
const isProduction = process.env.NODE_ENV === "production";

export default function Document() {

return (
<Html lang="en">
<Head>
{/* enable analytics script only for production */}
{isProduction && (
<>
<script
async
src={`https://www.googletagmanager.com/gtag/js?id=${GA_TRACKING_ID}`}
/>
<script
// eslint-disable-next-line react/no-danger
dangerouslySetInnerHTML={{
__html: `
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${GA_TRACKING_ID}', {
page_path: window.location.pathname,
});
`,
}}
/>
</>
)}
</Head>
<Head></Head>
<link rel="icon" href="/favicon.svg" />
<title>Close Loop on Cloud | LoopQuest</title>
<body>
Expand Down
1 change: 1 addition & 0 deletions loopquest/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from loopquest.api import init, is_initialized, make_env, close
Loading

0 comments on commit 3f09685

Please sign in to comment.