matsuap commited on
Commit
9c66a8b
·
1 Parent(s): 3d32f20

Update Dockerfile to streamline application setup by copying all contents and modifying the command to run multiple Python scripts concurrently.

Browse files
Files changed (3) hide show
  1. Dockerfile +8 -11
  2. numpy_server.py +17 -0
  3. scipy_server.py +19 -0
Dockerfile CHANGED
@@ -1,17 +1,14 @@
 
1
  FROM python:3.12-slim
2
 
3
- # Set the working directory
4
  WORKDIR /app
5
 
6
- # Copy the requirements file and install dependencies
7
- COPY ./requirements.txt /app/requirements.txt
8
- RUN pip install --no-cache-dir -r /app/requirements.txt
9
 
10
- # Copy the application code
11
- COPY ./app.py /app/app.py
12
 
13
- # Expose the port the app runs on
14
- EXPOSE 7860
15
-
16
- # Command to run the application
17
- CMD ["python", "/app/app.py"]
 
1
+ # Use an official Python runtime as a parent image
2
  FROM python:3.12-slim
3
 
4
+ # Set the working directory in the container
5
  WORKDIR /app
6
 
7
+ # Copy the current directory contents into the container at /app
8
+ COPY . /app
 
9
 
10
+ # Install any needed packages specified in requirements.txt
11
+ RUN pip install --no-cache-dir -r requirements.txt
12
 
13
+ # Run numpy_server.py and scipy_server.py
14
+ CMD ["sh", "-c", "python numpy_server.py & python scipy_server.py"]
 
 
 
numpy_server.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastmcp import FastMCP
2
+ import numpy as np
3
+
4
+ mcp = FastMCP()
5
+
6
+ @mcp.tool()
7
+ def numpy_add(a: list[float], b: list[float]) -> list[float]:
8
+ """Adds two vectors element-wise."""
9
+ return np.add(a, b).tolist()
10
+
11
+ @mcp.tool()
12
+ def numpy_multiply(a: list[float], b: list[float]) -> list[float]:
13
+ """Multiplies two vectors element-wise."""
14
+ return np.multiply(a, b).tolist()
15
+
16
+ if __name__ == "__main__":
17
+ mcp.run()
scipy_server.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastmcp import FastMCP
2
+ from scipy import stats
3
+
4
+ mcp = FastMCP()
5
+
6
+ @mcp.tool()
7
+ def scipy_ttest(a: list[float], b: list[float]) -> dict:
8
+ """Performs an independent two-sample t-test."""
9
+ t_stat, p_value = stats.ttest_ind(a, b)
10
+ return {"t_statistic": t_stat, "p_value": p_value}
11
+
12
+ @mcp.tool()
13
+ def scipy_pearsonr(x: list[float], y: list[float]) -> dict:
14
+ """Calculates the Pearson correlation coefficient."""
15
+ corr_coefficient, p_value = stats.pearsonr(x, y)
16
+ return {"correlation_coefficient": corr_coefficient, "p_value": p_value}
17
+
18
+ if __name__ == "__main__":
19
+ mcp.run()