diff --git a/.gitignore b/.gitignore index 222d4b8..3188c83 100644 --- a/.gitignore +++ b/.gitignore @@ -89,4 +89,9 @@ target/ .mypy_cache/ rewards-api/src/__pycache__ -rewards-api/__pycache__ \ No newline at end of file +rewards-api/__pycache__ +tmp.py +flaskApp.py +old_code +saved_models +temp.py \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index d240184..8923de6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,5 +19,4 @@ RUN mkdir rewards-api COPY ./rewards-api rewards-api WORKDIR "/rewards-api" EXPOSE 8900 -ENTRYPOINT [ "uvicorn", "main:app"] -CMD [ "--reload" ] \ No newline at end of file +CMD ["python", "main.py"] \ No newline at end of file diff --git a/README.md b/README.md index 945e8b2..ab3807c 100644 --- a/README.md +++ b/README.md @@ -1,22 +1,23 @@ -### **Rewards API** +### **Rewards API**
-**rewards API** is a `REST` API where creating experiments, integrating environments and building agents are just some sets of CRUD operations and API calls. Our API internally uses [**rewards-sdk**](https://github.com/rewards-ai/rewards-SDK). +**rewards API** is a `REST` API where creating experiments, integrating environments and building agents are just some sets of CRUD operations and API calls. Our API internally uses [**rewards-sdk**](https://github.com/rewards-ai/rewards-SDK).
-#### **How to run the project** +#### **How to run the project** First clone the project by running: + ```bash git clone https://github.com/rewards-ai/rewards-api.git ``` -`rewards-api` runs on `fastapi`. So install fastapi by running: +`rewards-api` runs on `flask`. So install fastapi by running: ```bash -pip install fastapi +pip install flask ``` Now for installing additional dependencies just run: @@ -28,15 +29,14 @@ pip install -r requirements.txt Now go to the `rewards-api` directory and run: ``` -uvicorn main:app --reload +python main.py ``` -This will open the the link `http://127.0.0.1:8000` and then go to `http://127.0.0.1:8000/docs/`. There you will find all the endpoints with it's instructions and curl commands after running each. - +This will open the the link `http://127.0.0.1:8000` and then go to `http://127.0.0.1:8000/docs/`. There you will find all the endpoints with it's instructions and curl commands after running each. TODO: - [ ] Logging functionality -- [ ] Support for custom exceptions +- [ ] Support for custom exceptions - [X] Supporting streaming the game screen -- [X] Integration with the frontend \ No newline at end of file +- [X] Integration with the frontend diff --git a/main.py b/main.py index c11e72a..b26d7e8 100644 --- a/main.py +++ b/main.py @@ -1,75 +1,41 @@ -import os -import json -import pygame -from fastapi.logger import logger -from fastapi import FastAPI, Request -from fastapi.responses import StreamingResponse -from fastapi.middleware.cors import CORSMiddleware -from fastapi.exceptions import RequestValidationError - -# configs and import from other modules - -from src.config import CONFIG -from src.schemas import ( - AgentConfiguration, - TrainingConfigurations, - EnvironmentConfigurations, - RewardFunction -) -from src.exceptions import ( - validation_exception_handler, - python_exception_handler -) - -import src.utils as utils -from src.streamer import RewardsStreamer - - -# TODO: -# ----- -# Add a response model for returning all the configuration in structured format -# Also add a error response model - - -app = FastAPI( - title="RewardsAI API for interacting with rewards-platform", - version="1.0.0", - description=""" - rewards-api is the easy to use API for interacting with agents and environments. - It enables users to easily create experiments and manage each of the experiments - by changing different types of parameters and reward function and also pushing the - model to other location while competing. - """ -) - -app.add_middleware( - CORSMiddleware, allow_origins=["*"], - allow_credentials=True, allow_methods=["*"], - allow_headers=["*"], -) -app.add_exception_handler(RequestValidationError, validation_exception_handler) -app.add_exception_handler(Exception, python_exception_handler) - -@app.on_event('startup') -async def startup_event(): +from rewards import QTrainer, LinearQNet, CarGame +from werkzeug.exceptions import HTTPException +from flask import Flask, Response, request, Request +from werkzeug.exceptions import NotFound +import matplotlib.pyplot as plt +from src.config import CONFIG +from flask_cors import CORS +import src.utils as utils +from flasgger import Swagger +import numpy as np +import json +import cv2 +import os + +app = Flask(__name__) +CORS(app) +Swagger(app) + +@app.before_first_request +def startup_event(): utils.create_folder_struct() - logger.info("Folder Created") - logger.info("Starting up") - + app.logger.info("Folder Created") + app.logger.info("Starting up") -@app.post('/api/v1/create_session/{session_id}') -def create_new_session(session_id : str): +@app.post('/api/v1/create_session') +def create_new_session(): """ - This create a new session in the rewards-platform where - user can now initialize with different environment, agent configuration. - - Args: - - - `session_id (str)`:The session ID is a unique string with a format of __