- Dockerfile +3 -3
- app.py +16 -4
Dockerfile
CHANGED
|
@@ -17,10 +17,10 @@ COPY ./requirements.txt requirements.txt
|
|
| 17 |
|
| 18 |
# Install the required Python packages
|
| 19 |
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
|
|
|
| 20 |
|
| 21 |
# Copy the application code
|
| 22 |
COPY . /app
|
| 23 |
|
| 24 |
-
# Run the FastAPI app
|
| 25 |
-
CMD ["
|
| 26 |
-
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]
|
|
|
|
| 17 |
|
| 18 |
# Install the required Python packages
|
| 19 |
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 20 |
+
RUN pip install python-json-logger
|
| 21 |
|
| 22 |
# Copy the application code
|
| 23 |
COPY . /app
|
| 24 |
|
| 25 |
+
# Run the FastAPI app
|
| 26 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]
|
|
|
app.py
CHANGED
|
@@ -1,14 +1,26 @@
|
|
| 1 |
from fastapi import FastAPI
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
app = FastAPI()
|
| 4 |
|
| 5 |
@app.on_event("startup")
|
| 6 |
async def startup_event():
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
print(f"FastAPI server started on {ip_address}:8000")
|
| 10 |
|
| 11 |
@app.post("/api/predict")
|
| 12 |
def predict(data: dict):
|
| 13 |
# L贸gica do endpoint
|
| 14 |
-
return {"result": "Resultado"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
+
from pythonjsonlogger import jsonlogger
|
| 3 |
+
import logging
|
| 4 |
+
import requests
|
| 5 |
+
|
| 6 |
+
# ... (rest of your logger setup)
|
| 7 |
|
| 8 |
app = FastAPI()
|
| 9 |
|
| 10 |
@app.on_event("startup")
|
| 11 |
async def startup_event():
|
| 12 |
+
ip_address = get_external_ip()
|
| 13 |
+
logger.info(f"FastAPI server started on {ip_address}:8000")
|
|
|
|
| 14 |
|
| 15 |
@app.post("/api/predict")
|
| 16 |
def predict(data: dict):
|
| 17 |
# L贸gica do endpoint
|
| 18 |
+
return {"result": "Resultado"}
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def get_external_ip():
|
| 22 |
+
try:
|
| 23 |
+
response = requests.get('https://ifconfig.me')
|
| 24 |
+
return response.text.strip()
|
| 25 |
+
except Exception as e:
|
| 26 |
+
return "IP lookup failed: {}".format(e)
|