aziac commited on
Commit
1eaa426
·
1 Parent(s): 78949d9

init fastapi commit

Browse files
Files changed (3) hide show
  1. Dockerfile +24 -0
  2. app/main.py +23 -0
  3. requirements.txt +3 -0
Dockerfile ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 /code
6
+
7
+ # Copy the requirements file into the container at /code
8
+ COPY ./requirements.txt /code/requirements.txt
9
+
10
+ # Install any needed packages specified in requirements.txt
11
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
12
+
13
+ # Copy the app and static directories into the container at /code
14
+ COPY ./app /code/app
15
+ COPY ./static /code/static
16
+
17
+ # Expose the port the app runs on. Hugging Face Spaces uses 7860 by default.
18
+ EXPOSE 7860
19
+
20
+ # Run uvicorn server.
21
+ # "app.main:app" -> find the `app` object in the `main.py` file inside the `app` folder.
22
+ # --host 0.0.0.0 makes it accessible from outside the container.
23
+ # --port 7860 to match the exposed port.
24
+ CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
app/main.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from fastapi.middleware.cors import CORSMiddleware
3
+
4
+ # Initialize the FastAPI app
5
+ app = FastAPI()
6
+
7
+ # --- CORS Middleware ---
8
+ # This is crucial for allowing your frontend to communicate with this backend.
9
+ # origins = ["*"] allows all origins, which is fine for this project.
10
+ # For a production application, you might want to restrict this to your frontend's domain.
11
+ app.add_middleware(
12
+ CORSMiddleware,
13
+ allow_origins=["*"], # Allows all origins
14
+ allow_credentials=True,
15
+ allow_methods=["*"], # Allows all methods (GET, POST, etc.)
16
+ allow_headers=["*"], # Allows all headers
17
+ )
18
+
19
+ # --- API Endpoints ---
20
+ @app.get("/")
21
+ async def read_root():
22
+ """A simple root endpoint to check if the API is running."""
23
+ return {"message": "Welcome to the Captcha Solver API!"}
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ fastapi
2
+ uvicorn[standard]
3
+ python-multipart