Anuj1729 commited on
Commit
5fc6331
·
verified ·
1 Parent(s): 5d551bc

Upload 3 files

Browse files
Files changed (3) hide show
  1. Dockerfile +12 -0
  2. main.py +99 -0
  3. requirements.txt +22 -0
Dockerfile ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.11-slim
2
+
3
+ WORKDIR /app
4
+
5
+ COPY requirements.txt .
6
+ RUN pip install --no-cache-dir -r requirements.txt
7
+
8
+ COPY main.py .
9
+
10
+ EXPOSE 7860
11
+
12
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
main.py ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from fastapi.middleware.cors import CORSMiddleware
3
+ from pydantic import BaseModel
4
+ from typing import List
5
+ import anthropic
6
+ import os
7
+ from dotenv import load_dotenv
8
+
9
+ load_dotenv()
10
+
11
+ app = FastAPI()
12
+
13
+ # Allow React frontend to talk to backend
14
+ app.add_middleware(
15
+ CORSMiddleware,
16
+ allow_origins=[
17
+ "http://localhost:3000",
18
+ "https://anuj1729-collegeedge-frontend.hf.space",
19
+ ],
20
+ allow_credentials=True,
21
+ allow_methods=["*"],
22
+ allow_headers=["*"],
23
+ )
24
+
25
+ # --- Models ---
26
+ class ChildProfile(BaseModel):
27
+ name: str
28
+ grade: int # 6 to 12
29
+ interests: List[str] # e.g. ["coding", "music", "sports"]
30
+ dream_colleges: List[str] # e.g. ["MIT", "Stanford"]
31
+ career_goals: str # e.g. "I want to be a software engineer"
32
+
33
+ class Plan(BaseModel):
34
+ activities: List[str]
35
+ volunteering: List[str]
36
+ summer_programs: List[str]
37
+ skills_certifications: List[str]
38
+ monthly_tracker: List[str]
39
+ essay_topics: List[str]
40
+
41
+
42
+ # --- Helper: Build AI Prompt ---
43
+ def build_prompt(profile: ChildProfile) -> str:
44
+ return f"""
45
+ You are a college admissions expert helping parents build a personalized
46
+ college readiness plan for their child.
47
+
48
+ Child Profile:
49
+ - Name: {profile.name}
50
+ - Grade: {profile.grade}
51
+ - Interests: {", ".join(profile.interests)}
52
+ - Dream Colleges: {", ".join(profile.dream_colleges)}
53
+ - Career Goals: {profile.career_goals}
54
+
55
+ Generate a personalized college readiness plan with exactly these 6 sections.
56
+ Respond ONLY in valid JSON with these exact keys, no extra text:
57
+
58
+ {{
59
+ "activities": ["5 specific club or activity recommendations"],
60
+ "volunteering": ["5 specific volunteering opportunities"],
61
+ "summer_programs": ["5 specific summer program suggestions"],
62
+ "skills_certifications": ["5 specific skills or certifications to pursue"],
63
+ "monthly_tracker": ["12 monthly goals from January to December"],
64
+ "essay_topics": ["5 college essay topic ideas based on their profile"]
65
+ }}
66
+ """
67
+
68
+
69
+ # --- Routes ---
70
+ @app.get("/")
71
+ def root():
72
+ return {"message": "CollegeEdge API is running!"}
73
+
74
+
75
+ @app.post("/generate-plan", response_model=Plan)
76
+ def generate_plan(profile: ChildProfile):
77
+ client = anthropic.Anthropic(api_key=os.getenv("ANTHROPIC_API_KEY"))
78
+
79
+ message = client.messages.create(
80
+ model="claude-opus-4-6",
81
+ max_tokens=2000,
82
+ messages=[
83
+ {"role": "user", "content": build_prompt(profile)}
84
+ ]
85
+ )
86
+
87
+ import json
88
+ import re
89
+
90
+ raw = message.content[0].text.strip()
91
+
92
+ # Strip markdown code blocks if Claude wraps response in ```json ... ```
93
+ raw = re.sub(r"```json|```", "", raw).strip()
94
+
95
+ if not raw:
96
+ raise ValueError("Empty response from Claude")
97
+
98
+ parsed = json.loads(raw)
99
+ return Plan(**parsed)
requirements.txt ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ annotated-doc==0.0.4
2
+ annotated-types==0.7.0
3
+ anthropic==0.84.0
4
+ anyio==4.12.1
5
+ certifi==2026.2.25
6
+ click==8.3.1
7
+ distro==1.9.0
8
+ docstring_parser==0.17.0
9
+ fastapi==0.135.1
10
+ h11==0.16.0
11
+ httpcore==1.0.9
12
+ httpx==0.28.1
13
+ idna==3.11
14
+ jiter==0.13.0
15
+ pydantic==2.12.5
16
+ pydantic_core==2.41.5
17
+ python-dotenv==1.2.2
18
+ sniffio==1.3.1
19
+ starlette==0.52.1
20
+ typing-inspection==0.4.2
21
+ typing_extensions==4.15.0
22
+ uvicorn==0.41.0