Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -8,7 +8,7 @@ from gradio.routes import mount_gradio_app
|
|
8 |
from retriever import get_relevant_passages
|
9 |
from reranker import rerank
|
10 |
|
11 |
-
#
|
12 |
app = FastAPI()
|
13 |
|
14 |
# --- Load and clean CSV ---
|
@@ -77,7 +77,25 @@ def recommend(query):
|
|
77 |
print(traceback.format_exc())
|
78 |
return {"error": f"Error processing request: {str(e)}"}
|
79 |
|
80 |
-
# ---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
iface = gr.Interface(
|
82 |
fn=recommend,
|
83 |
inputs=gr.Textbox(label="Enter Job Description", lines=4),
|
@@ -86,39 +104,5 @@ iface = gr.Interface(
|
|
86 |
description="Paste a job description to get the most relevant SHL assessments."
|
87 |
)
|
88 |
|
89 |
-
# ✅ Mount Gradio
|
90 |
mount_gradio_app(app, iface, path="/")
|
91 |
-
|
92 |
-
# --- Health Endpoint ---
|
93 |
-
@app.get("/health")
|
94 |
-
async def health_check():
|
95 |
-
return JSONResponse(
|
96 |
-
content={"status": "healthy"},
|
97 |
-
media_type="application/json",
|
98 |
-
status_code=200
|
99 |
-
)
|
100 |
-
|
101 |
-
# --- API Recommendation Endpoint ---
|
102 |
-
@app.post("/recommend")
|
103 |
-
async def recommend_api(request: Request):
|
104 |
-
try:
|
105 |
-
body = await request.json()
|
106 |
-
query = body.get("query", "").strip()
|
107 |
-
if not query:
|
108 |
-
return JSONResponse(
|
109 |
-
content={"error": "Missing 'query' in request body"},
|
110 |
-
media_type="application/json",
|
111 |
-
status_code=400
|
112 |
-
)
|
113 |
-
result = recommend(query)
|
114 |
-
return JSONResponse(
|
115 |
-
content=result,
|
116 |
-
media_type="application/json",
|
117 |
-
status_code=200
|
118 |
-
)
|
119 |
-
except Exception as e:
|
120 |
-
return JSONResponse(
|
121 |
-
content={"error": str(e)},
|
122 |
-
media_type="application/json",
|
123 |
-
status_code=500
|
124 |
-
)
|
|
|
8 |
from retriever import get_relevant_passages
|
9 |
from reranker import rerank
|
10 |
|
11 |
+
# ✅ Top-level FastAPI app declaration
|
12 |
app = FastAPI()
|
13 |
|
14 |
# --- Load and clean CSV ---
|
|
|
77 |
print(traceback.format_exc())
|
78 |
return {"error": f"Error processing request: {str(e)}"}
|
79 |
|
80 |
+
# --- FastAPI Health Endpoint ---
|
81 |
+
@app.get("/health")
|
82 |
+
async def health():
|
83 |
+
return JSONResponse(content={"status": "healthy"}, status_code=200)
|
84 |
+
|
85 |
+
# --- FastAPI Recommendation API ---
|
86 |
+
@app.post("/recommend")
|
87 |
+
async def recommend_api(request: Request):
|
88 |
+
try:
|
89 |
+
data = await request.json()
|
90 |
+
query = data.get("query", "").strip()
|
91 |
+
if not query:
|
92 |
+
return JSONResponse(content={"error": "Missing query"}, status_code=400)
|
93 |
+
result = recommend(query)
|
94 |
+
return JSONResponse(content=result, status_code=200)
|
95 |
+
except Exception as e:
|
96 |
+
return JSONResponse(content={"error": str(e)}, status_code=500)
|
97 |
+
|
98 |
+
# --- Gradio UI ---
|
99 |
iface = gr.Interface(
|
100 |
fn=recommend,
|
101 |
inputs=gr.Textbox(label="Enter Job Description", lines=4),
|
|
|
104 |
description="Paste a job description to get the most relevant SHL assessments."
|
105 |
)
|
106 |
|
107 |
+
# ✅ Mount Gradio at root
|
108 |
mount_gradio_app(app, iface, path="/")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|