Jsupremo commited on
Commit
fcd774e
路
1 Parent(s): 0e266cb
Files changed (2) hide show
  1. Dockerfile +3 -3
  2. 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 with IP address printed
25
- CMD ["sh", "-c", "echo 'Real IP address: $(ip route get 1 | awk '{print $NF;exit}')'; uvicorn app:app --host 0.0.0.0 --port 8000"]
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
- # Get the IP address
8
- ip_address = (await app.state.get_connection()).host
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)