Spaces:
Sleeping
Sleeping
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -11068,15 +11068,9 @@ examples = [
|
|
| 11068 |
["Logical reasoning and problem solving test"],
|
| 11069 |
]
|
| 11070 |
|
| 11071 |
-
# Build the Gradio interface
|
| 11072 |
with gr.Blocks(
|
| 11073 |
-
title="SHL Assessment Recommendation Engine"
|
| 11074 |
-
theme=gr.themes.Soft(
|
| 11075 |
-
primary_hue="blue",
|
| 11076 |
-
secondary_hue="purple",
|
| 11077 |
-
neutral_hue="slate",
|
| 11078 |
-
),
|
| 11079 |
-
css=custom_css
|
| 11080 |
) as demo:
|
| 11081 |
|
| 11082 |
# Header
|
|
@@ -11155,40 +11149,26 @@ with gr.Blocks(
|
|
| 11155 |
|
| 11156 |
|
| 11157 |
# ============================================================================
|
| 11158 |
-
# FASTAPI INTEGRATION FOR API
|
| 11159 |
# ============================================================================
|
| 11160 |
|
| 11161 |
-
|
| 11162 |
-
from fastapi
|
| 11163 |
-
|
| 11164 |
-
app = FastAPI(
|
| 11165 |
-
title="SHL Assessment Recommendation API",
|
| 11166 |
-
description="AI-powered assessment recommendations using 2-Stage RAG Pipeline",
|
| 11167 |
-
version="2.0.0"
|
| 11168 |
-
)
|
| 11169 |
|
| 11170 |
-
|
| 11171 |
-
|
| 11172 |
-
allow_origins=["*"],
|
| 11173 |
-
allow_credentials=True,
|
| 11174 |
-
allow_methods=["*"],
|
| 11175 |
-
allow_headers=["*"],
|
| 11176 |
-
)
|
| 11177 |
|
| 11178 |
-
|
|
|
|
| 11179 |
def health_check():
|
| 11180 |
"""Health check endpoint - returns exactly {status: healthy}"""
|
| 11181 |
return {"status": "healthy"}
|
| 11182 |
|
| 11183 |
-
|
| 11184 |
-
|
| 11185 |
-
class RecommendRequest(BaseModel):
|
| 11186 |
-
query: str
|
| 11187 |
-
|
| 11188 |
-
@app.get("/recommend")
|
| 11189 |
def recommend_api_get(
|
| 11190 |
-
query: str =
|
| 11191 |
-
max_results: int =
|
| 11192 |
):
|
| 11193 |
"""Get assessment recommendations as JSON (GET method)"""
|
| 11194 |
results = engine.recommend(query.strip(), max_results=max_results)
|
|
@@ -11196,7 +11176,7 @@ def recommend_api_get(
|
|
| 11196 |
"recommended_assessments": results
|
| 11197 |
}
|
| 11198 |
|
| 11199 |
-
@app.post("/recommend")
|
| 11200 |
def recommend_api_post(request: RecommendRequest):
|
| 11201 |
"""Get assessment recommendations as JSON (POST method)"""
|
| 11202 |
results = engine.recommend(request.query.strip(), max_results=10)
|
|
@@ -11204,13 +11184,12 @@ def recommend_api_post(request: RecommendRequest):
|
|
| 11204 |
"recommended_assessments": results
|
| 11205 |
}
|
| 11206 |
|
| 11207 |
-
# Mount Gradio app to FastAPI
|
| 11208 |
-
app = gr.mount_gradio_app(app, demo, path="/")
|
| 11209 |
-
|
| 11210 |
# ============================================================================
|
| 11211 |
# LAUNCH APPLICATION
|
| 11212 |
# ============================================================================
|
| 11213 |
|
| 11214 |
if __name__ == "__main__":
|
| 11215 |
-
|
| 11216 |
-
|
|
|
|
|
|
|
|
|
| 11068 |
["Logical reasoning and problem solving test"],
|
| 11069 |
]
|
| 11070 |
|
| 11071 |
+
# Build the Gradio interface - Gradio 6.0 compatible
|
| 11072 |
with gr.Blocks(
|
| 11073 |
+
title="SHL Assessment Recommendation Engine"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11074 |
) as demo:
|
| 11075 |
|
| 11076 |
# Header
|
|
|
|
| 11149 |
|
| 11150 |
|
| 11151 |
# ============================================================================
|
| 11152 |
+
# FASTAPI/GRADIO INTEGRATION FOR API ENDPOINTS
|
| 11153 |
# ============================================================================
|
| 11154 |
|
| 11155 |
+
# Import FastAPI requirements
|
| 11156 |
+
from fastapi import Query as FastAPIQuery
|
| 11157 |
+
from pydantic import BaseModel
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11158 |
|
| 11159 |
+
class RecommendRequest(BaseModel):
|
| 11160 |
+
query: str
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11161 |
|
| 11162 |
+
# Add API routes to Gradio's built-in FastAPI app
|
| 11163 |
+
@demo.app.get("/health")
|
| 11164 |
def health_check():
|
| 11165 |
"""Health check endpoint - returns exactly {status: healthy}"""
|
| 11166 |
return {"status": "healthy"}
|
| 11167 |
|
| 11168 |
+
@demo.app.get("/recommend")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11169 |
def recommend_api_get(
|
| 11170 |
+
query: str = FastAPIQuery(..., min_length=3, description="Job description or requirements"),
|
| 11171 |
+
max_results: int = FastAPIQuery(default=10, ge=1, le=10, description="Max results")
|
| 11172 |
):
|
| 11173 |
"""Get assessment recommendations as JSON (GET method)"""
|
| 11174 |
results = engine.recommend(query.strip(), max_results=max_results)
|
|
|
|
| 11176 |
"recommended_assessments": results
|
| 11177 |
}
|
| 11178 |
|
| 11179 |
+
@demo.app.post("/recommend")
|
| 11180 |
def recommend_api_post(request: RecommendRequest):
|
| 11181 |
"""Get assessment recommendations as JSON (POST method)"""
|
| 11182 |
results = engine.recommend(request.query.strip(), max_results=10)
|
|
|
|
| 11184 |
"recommended_assessments": results
|
| 11185 |
}
|
| 11186 |
|
|
|
|
|
|
|
|
|
|
| 11187 |
# ============================================================================
|
| 11188 |
# LAUNCH APPLICATION
|
| 11189 |
# ============================================================================
|
| 11190 |
|
| 11191 |
if __name__ == "__main__":
|
| 11192 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|
| 11193 |
+
else:
|
| 11194 |
+
# For HuggingFace Spaces - just expose the app
|
| 11195 |
+
app = demo.app
|