Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- Dockerfile +24 -0
- requirements.txt +2 -0
- server.py +60 -0
Dockerfile
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Use a slim Python image
|
| 2 |
+
FROM python:3.11-slim
|
| 3 |
+
|
| 4 |
+
# Set working directory
|
| 5 |
+
WORKDIR /app
|
| 6 |
+
|
| 7 |
+
# Install system dependencies (needed for some python libs)
|
| 8 |
+
RUN apt-get update && apt-get install -y \
|
| 9 |
+
build-essential \
|
| 10 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 11 |
+
|
| 12 |
+
# Copy requirements first for better caching
|
| 13 |
+
COPY requirements.txt .
|
| 14 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 15 |
+
|
| 16 |
+
# Copy the rest of your application and resources
|
| 17 |
+
COPY . .
|
| 18 |
+
|
| 19 |
+
# Expose the port Hugging Face uses
|
| 20 |
+
EXPOSE 7860
|
| 21 |
+
|
| 22 |
+
# Run the server using the SSE transport
|
| 23 |
+
# We point to port 7860 as required by HF
|
| 24 |
+
CMD ["python", "math_server.py", "--transport", "sse", "--port", "7860"]
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
mcp[cli]
|
| 2 |
+
fastmcp
|
server.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from mcp.server.fastmcp import FastMCP
|
| 2 |
+
import logging
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
# Initialize the server
|
| 6 |
+
mcp = FastMCP("Math-Education-Server")
|
| 7 |
+
|
| 8 |
+
current_dir = os.path.dirname(os.path.abspath(__file__))
|
| 9 |
+
|
| 10 |
+
# Path to your collected resource
|
| 11 |
+
MARKDOWN_FILE = r"resource\jemh114-min (1).md"
|
| 12 |
+
|
| 13 |
+
def get_local_resource():
|
| 14 |
+
"""Helper to read the markdown file safely."""
|
| 15 |
+
if os.path.exists(MARKDOWN_FILE):
|
| 16 |
+
with open(MARKDOWN_FILE, "r", encoding="utf-8") as f:
|
| 17 |
+
return f.read()
|
| 18 |
+
return "Resource file not found."
|
| 19 |
+
|
| 20 |
+
# --- Task 1: Generate a Summary ---
|
| 21 |
+
@mcp.tool()
|
| 22 |
+
async def generate_chapter_summary(chapter_name: str) -> str:
|
| 23 |
+
"""
|
| 24 |
+
Provides the source material for a chapter.
|
| 25 |
+
The AI should use this to create a summary.
|
| 26 |
+
"""
|
| 27 |
+
raw_data = get_local_resource()
|
| 28 |
+
|
| 29 |
+
# We use XML-style tags. Senior engineers do this because
|
| 30 |
+
# LLMs (especially Claude) are trained to handle tagged data perfectly.
|
| 31 |
+
return f"""
|
| 32 |
+
<source_material>
|
| 33 |
+
{raw_data[:4000]}
|
| 34 |
+
</source_material>
|
| 35 |
+
|
| 36 |
+
SYSTEM_INSTRUCTION: You are a Mathematics Expert.
|
| 37 |
+
1. Read the text inside <source_material>.
|
| 38 |
+
2. Create a summary with 3 bullet points.
|
| 39 |
+
3. List all formulas found in LaTeX format.
|
| 40 |
+
4. Do not repeat the raw text; only provide the summary.
|
| 41 |
+
"""
|
| 42 |
+
|
| 43 |
+
# --- Task 2: Quiz Generator ---
|
| 44 |
+
@mcp.tool()
|
| 45 |
+
async def generate_quiz(chapter_name: str, difficulty: str = "medium") -> str:
|
| 46 |
+
"""
|
| 47 |
+
Extracts formulas from the markdown and asks the LLM to build a quiz.
|
| 48 |
+
"""
|
| 49 |
+
raw_data = get_local_resource()
|
| 50 |
+
|
| 51 |
+
# Using the LLM's ability to pick out formulas from the raw text provided
|
| 52 |
+
return (
|
| 53 |
+
f"Here is the raw material for {chapter_name}:\n"
|
| 54 |
+
f"{raw_data}\n"
|
| 55 |
+
f"Difficulty: {difficulty}\n"
|
| 56 |
+
"Task: Create a 3-question quiz using the formulas found in the text."
|
| 57 |
+
)
|
| 58 |
+
|
| 59 |
+
if __name__ == "__main__":
|
| 60 |
+
mcp.run(transport="stdio")
|