justKevv commited on
Commit
abf024a
·
1 Parent(s): 79a6a3c

feat: new controller and databse connection

Browse files
Files changed (7) hide show
  1. .env.example +2 -0
  2. .gitignore +5 -0
  3. README.md +3 -2
  4. app.py +7 -0
  5. controller.py +14 -0
  6. database.py +28 -0
  7. requirements.txt +1 -0
.env.example ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ SUPABASE_URL="YOUR_SUPABASE_URL"
2
+ SUPABASE_KEY="YOUR_SUPABASE_ANON_KEY"
.gitignore ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ venv
2
+ env
3
+ .env
4
+ __pycache__
5
+ model
README.md CHANGED
@@ -1,12 +1,13 @@
1
  ---
2
  title: Predictive Machine
3
- emoji: 📊
4
  colorFrom: pink
5
  colorTo: indigo
6
  sdk: docker
7
- pinned: false
8
  license: apache-2.0
9
  short_description: Predictive Machine Copilot for Asah by Dicoding x Accenture
 
10
  ---
11
 
12
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
  title: Predictive Machine
3
+ emoji: 🚨
4
  colorFrom: pink
5
  colorTo: indigo
6
  sdk: docker
7
+ pinned: true
8
  license: apache-2.0
9
  short_description: Predictive Machine Copilot for Asah by Dicoding x Accenture
10
+ datasets: https://www.kaggle.com/datasets/shivamb/machine-predictive-maintenance-classification/data
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py CHANGED
@@ -1,7 +1,14 @@
1
  from fastapi import FastAPI
2
 
 
 
3
  app = FastAPI()
 
4
 
5
  @app.get("/")
6
  def greet_json():
7
  return {"Hello": "World!"}
 
 
 
 
 
1
  from fastapi import FastAPI
2
 
3
+ from database import Database
4
+
5
  app = FastAPI()
6
+ database = Database()
7
 
8
  @app.get("/")
9
  def greet_json():
10
  return {"Hello": "World!"}
11
+
12
+ @app.get("/predict-machine")
13
+ def predict_machine():
14
+ return database.get_sensor_readings()
controller.py ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from database import Database
2
+
3
+ class Controller():
4
+ def __init__(self):
5
+ self.__database = Database()
6
+ self.__sensor = self.__database.get_sensor_readings()
7
+
8
+ # Binary method
9
+
10
+ # Classification Method
11
+
12
+ # Time series method
13
+ def predict_time_series(self):
14
+ self.__sensor
database.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from dotenv import load_dotenv
3
+ from supabase import create_client, Client
4
+
5
+ load_dotenv()
6
+
7
+ class Database():
8
+ def __init__(self):
9
+ self.__url = os.environ.get("SUPABASE_URL") or ""
10
+ self.__key: str = os.environ.get("SUPABASE_KEY") or ""
11
+
12
+ if not self.__url or not self.__key:
13
+ raise ValueError("SUPABASE_URL or SUPABASE_KEY is missing in environment")
14
+
15
+ self.__supabase: Client = create_client(self.__url, self.__key)
16
+
17
+ def get_sensor_readings(self):
18
+ response = (
19
+ self.__supabase.table("sensor_readings")
20
+ .select("*")
21
+ .order("created_at", desc=True)
22
+ .limit(1)
23
+ .execute()
24
+ )
25
+
26
+ if response.data:
27
+ return response.data[0]
28
+ return None
requirements.txt CHANGED
@@ -1,2 +1,3 @@
1
  fastapi[standard]
2
  uvicorn[standard]
 
 
1
  fastapi[standard]
2
  uvicorn[standard]
3
+ supabase