Sushan commited on
Commit
7aa2125
·
1 Parent(s): 5893f86

Model deployed

Browse files
Files changed (5) hide show
  1. Dockerfile +17 -0
  2. app.py +29 -0
  3. model.pkl +3 -0
  4. requirements.txt +5 -0
  5. test.py +19 -0
Dockerfile ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use an official Python runtime as a parent image
2
+ FROM python:3.9-slim
3
+
4
+ # Set the working directory in the container
5
+ WORKDIR /app
6
+
7
+ # Copy the current directory contents into the container
8
+ COPY . /app
9
+
10
+ # Install the required packages from requirements.txt
11
+ RUN pip install --no-cache-dir -r requirements.txt
12
+
13
+ # Expose port 8000 for the FastAPI app
14
+ EXPOSE 8000
15
+
16
+ # Command to run the FastAPI app with Uvicorn
17
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from fastapi.middleware.cors import CORSMiddleware
3
+ import pandas as pd
4
+ import joblib
5
+
6
+ # Load the trained model
7
+ model = joblib.load("model.pkl") # Ensure your model is saved as 'model.pkl'
8
+
9
+ app = FastAPI()
10
+
11
+ # Add CORS middleware to allow requests from any origin
12
+ app.add_middleware(
13
+ CORSMiddleware,
14
+ allow_origins=["*"], # Allow all origins (adjust if needed)
15
+ allow_credentials=True,
16
+ allow_methods=["*"], # Allow all methods (GET, POST, etc.)
17
+ allow_headers=["*"], # Allow all headers
18
+ )
19
+
20
+ @app.post("/predict")
21
+ async def predict(features: dict):
22
+ # Convert the input into a DataFrame
23
+ input_data = pd.DataFrame([features])
24
+
25
+ # Make prediction using the trained model
26
+ prediction = model.predict(input_data)
27
+
28
+ return {"is_potentially_hazardous_asteroid": int(prediction[0])}
29
+
model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:21c23c7f17c0d72b85d0b416e14f01a70ee56833197740ee5ce168819b15148f
3
+ size 3870
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ fastapi
2
+ uvicorn
3
+ pandas
4
+ scikit-learn
5
+ joblib
test.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+
3
+ # URL of the deployed API (replace with your actual space URL)
4
+ url = "https://<your-space-name>.hf.space/predict"
5
+
6
+ # Sample input data
7
+ data = {
8
+ "absolute_magnitude_h": 22.1,
9
+ "estimated_diameter_min_km": 0.127,
10
+ "estimated_diameter_max_km": 0.285,
11
+ "relative_velocity_km_per_sec": 5.67,
12
+ "miss_distance_km": 386000.0
13
+ }
14
+
15
+ # Make a request to the API
16
+ response = requests.post(url, json=data)
17
+
18
+ # Display the prediction result
19
+ print(response.json())