matsuap commited on
Commit
42fc79a
·
1 Parent(s): 0676433

Refactor application structure by removing separate server scripts and integrating functionality into app.py; add independent two-sample t-test and Pearson correlation coefficient tools using SciPy.

Browse files
Files changed (6) hide show
  1. Dockerfile +11 -8
  2. app.py +21 -0
  3. main.py +0 -18
  4. numpy_server.py +0 -17
  5. requirements.txt +0 -2
  6. scipy_server.py +0 -19
Dockerfile CHANGED
@@ -1,14 +1,17 @@
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 main.py to start the FastAPI server
14
- CMD ["python", "main.py"]
 
 
 
 
 
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"]
app.py CHANGED
@@ -2,6 +2,7 @@ from fastmcp import FastMCP
2
  import numpy as np
3
  from pydantic import BaseModel
4
  from typing import List, Tuple, Optional
 
5
 
6
  mcp = FastMCP("Demo 🚀")
7
 
@@ -228,5 +229,25 @@ def summarize_request(input: SummarizeRequestInput) -> str:
228
  """Generate a prompt asking for a summary."""
229
  return f"Please summarize the following text:\n\n{input.text}"
230
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
231
  if __name__ == "__main__":
232
  mcp.run(transport="sse", host="0.0.0.0", port=7860)
 
2
  import numpy as np
3
  from pydantic import BaseModel
4
  from typing import List, Tuple, Optional
5
+ from scipy import stats
6
 
7
  mcp = FastMCP("Demo 🚀")
8
 
 
229
  """Generate a prompt asking for a summary."""
230
  return f"Please summarize the following text:\n\n{input.text}"
231
 
232
+ class ScipyTtestInput(BaseModel):
233
+ a: List[float]
234
+ b: List[float]
235
+
236
+ @mcp.tool()
237
+ def scipy_ttest(input: ScipyTtestInput) -> dict:
238
+ """Performs an independent two-sample t-test."""
239
+ t_stat, p_value = stats.ttest_ind(input.a, input.b)
240
+ return {"t_statistic": t_stat, "p_value": p_value}
241
+
242
+ class ScipyPearsonrInput(BaseModel):
243
+ x: List[float]
244
+ y: List[float]
245
+
246
+ @mcp.tool()
247
+ def scipy_pearsonr(input: ScipyPearsonrInput) -> dict:
248
+ """Calculates the Pearson correlation coefficient."""
249
+ corr_coefficient, p_value = stats.pearsonr(input.x, input.y)
250
+ return {"correlation_coefficient": corr_coefficient, "p_value": p_value}
251
+
252
  if __name__ == "__main__":
253
  mcp.run(transport="sse", host="0.0.0.0", port=7860)
main.py DELETED
@@ -1,18 +0,0 @@
1
- import os
2
- import uvicorn
3
- from fastapi import FastAPI
4
-
5
- # Import the FastMCP instances from numpy_server and scipy_server
6
- from numpy_server import mcp as numpy_mcp
7
- from scipy_server import mcp as scipy_mcp
8
-
9
- # Main FastAPI instance
10
- app = FastAPI()
11
-
12
- # Mount the sub-applications on different paths
13
- app.mount("/numpy", numpy_mcp.app)
14
- app.mount("/scipy", scipy_mcp.app)
15
-
16
- if __name__ == "__main__":
17
- port = int(os.environ.get("PORT", 7860))
18
- uvicorn.run("main:app", host="0.0.0.0", port=port, reload=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
numpy_server.py DELETED
@@ -1,17 +0,0 @@
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()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
requirements.txt CHANGED
@@ -1,5 +1,3 @@
1
  fastmcp
2
  numpy
3
  scipy
4
- fastapi
5
- uvicorn
 
1
  fastmcp
2
  numpy
3
  scipy
 
 
scipy_server.py DELETED
@@ -1,19 +0,0 @@
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()