Spaces:
Sleeping
Sleeping
Sushan
commited on
Commit
·
6f5baa5
1
Parent(s):
8b2caaf
hope it works
Browse files- Dockerfile +4 -4
- app.py +8 -1
- test.py +11 -6
Dockerfile
CHANGED
|
@@ -10,8 +10,8 @@ COPY . /app
|
|
| 10 |
# Install the required packages from requirements.txt
|
| 11 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 12 |
|
| 13 |
-
# Expose
|
| 14 |
-
EXPOSE
|
| 15 |
|
| 16 |
-
#
|
| 17 |
-
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "
|
|
|
|
| 10 |
# Install the required packages from requirements.txt
|
| 11 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 12 |
|
| 13 |
+
# Expose the correct port
|
| 14 |
+
EXPOSE 7860
|
| 15 |
|
| 16 |
+
# Run the FastAPI app on the expected port (7860)
|
| 17 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
app.py
CHANGED
|
@@ -20,7 +20,7 @@ class AsteroidModel(torch.nn.Module):
|
|
| 20 |
|
| 21 |
# Initialize the model and load the saved weights
|
| 22 |
model = AsteroidModel()
|
| 23 |
-
model.load_state_dict(torch.load('model.pth'))
|
| 24 |
model.eval() # Set model to evaluation mode
|
| 25 |
|
| 26 |
app = FastAPI()
|
|
@@ -46,3 +46,10 @@ async def predict(features: dict):
|
|
| 46 |
prediction = (output > 0.5).float().item() # Convert to binary prediction
|
| 47 |
|
| 48 |
return {"is_potentially_hazardous_asteroid": int(prediction)}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
# Initialize the model and load the saved weights
|
| 22 |
model = AsteroidModel()
|
| 23 |
+
model.load_state_dict(torch.load('model.pth', weights_only=True))
|
| 24 |
model.eval() # Set model to evaluation mode
|
| 25 |
|
| 26 |
app = FastAPI()
|
|
|
|
| 46 |
prediction = (output > 0.5).float().item() # Convert to binary prediction
|
| 47 |
|
| 48 |
return {"is_potentially_hazardous_asteroid": int(prediction)}
|
| 49 |
+
|
| 50 |
+
import os
|
| 51 |
+
|
| 52 |
+
if __name__ == "__main__":
|
| 53 |
+
import uvicorn
|
| 54 |
+
port = int(os.environ.get("PORT", 7860)) # Set the default port to 7860
|
| 55 |
+
uvicorn.run("app:app", host="0.0.0.0", port=port)
|
test.py
CHANGED
|
@@ -1,9 +1,9 @@
|
|
| 1 |
import requests
|
| 2 |
|
| 3 |
-
#
|
| 4 |
-
url = "https
|
| 5 |
|
| 6 |
-
# Sample input data
|
| 7 |
data = {
|
| 8 |
"absolute_magnitude_h": 22.1,
|
| 9 |
"estimated_diameter_min_km": 0.127,
|
|
@@ -12,8 +12,13 @@ data = {
|
|
| 12 |
"miss_distance_km": 386000.0
|
| 13 |
}
|
| 14 |
|
| 15 |
-
# Make a request to the API
|
| 16 |
response = requests.post(url, json=data)
|
| 17 |
|
| 18 |
-
#
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import requests
|
| 2 |
|
| 3 |
+
# Replace with your actual Hugging Face Spaces URL
|
| 4 |
+
url = "https://sushanadhikari-orreryspaceapp.hf.space/predict"
|
| 5 |
|
| 6 |
+
# Sample input data based on the features used in your model
|
| 7 |
data = {
|
| 8 |
"absolute_magnitude_h": 22.1,
|
| 9 |
"estimated_diameter_min_km": 0.127,
|
|
|
|
| 12 |
"miss_distance_km": 386000.0
|
| 13 |
}
|
| 14 |
|
| 15 |
+
# Make a POST request to the API
|
| 16 |
response = requests.post(url, json=data)
|
| 17 |
|
| 18 |
+
# Check if the request was successful
|
| 19 |
+
if response.status_code == 200:
|
| 20 |
+
# Print the model's prediction
|
| 21 |
+
print("Response from the model:", response.json())
|
| 22 |
+
else:
|
| 23 |
+
print(f"Failed to get a response, status code: {response.status_code}")
|
| 24 |
+
print("Error details:", response.text)
|