Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -101,28 +101,40 @@ async def recommend_api(request: Request):
|
|
101 |
except Exception as e:
|
102 |
return JSONResponse(content={"error": str(e)}, status_code=500)
|
103 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
@app.get("/")
|
105 |
async def root():
|
106 |
-
return RedirectResponse(url="/
|
107 |
-
|
108 |
-
# === Create Gradio Interface ===
|
109 |
-
def create_gr_interface():
|
110 |
-
return gr.Interface(
|
111 |
-
fn=recommend,
|
112 |
-
inputs=gr.Textbox(label="Enter Job Description", lines=4, placeholder="Paste a job description here..."),
|
113 |
-
outputs=gr.JSON(),
|
114 |
-
title="SHL Assessment Recommender",
|
115 |
-
description="Paste a job description to get the most relevant SHL assessments.",
|
116 |
-
theme=gr.themes.Soft(),
|
117 |
-
allow_flagging="never"
|
118 |
-
)
|
119 |
|
120 |
-
#
|
121 |
-
|
122 |
-
gr_app = create_gr_interface()
|
123 |
-
app = gr.mount_gradio_app(app, gr_app, path="/gradio")
|
124 |
|
125 |
-
#
|
126 |
if __name__ == "__main__":
|
127 |
import uvicorn
|
128 |
-
|
|
|
|
|
|
|
|
101 |
except Exception as e:
|
102 |
return JSONResponse(content={"error": str(e)}, status_code=500)
|
103 |
|
104 |
+
|
105 |
+
# === Create Gradio Interface as a Separate App ===
|
106 |
+
# For newer Gradio versions (5.x), create a standalone Gradio app
|
107 |
+
with gr.Blocks(title="SHL Assessment Recommender") as demo:
|
108 |
+
gr.Markdown("# SHL Assessment Recommender")
|
109 |
+
gr.Markdown("Paste a job description to get the most relevant SHL assessments.")
|
110 |
+
|
111 |
+
with gr.Row():
|
112 |
+
job_description = gr.Textbox(
|
113 |
+
label="Enter Job Description",
|
114 |
+
lines=4,
|
115 |
+
placeholder="Paste a job description here..."
|
116 |
+
)
|
117 |
+
|
118 |
+
with gr.Row():
|
119 |
+
submit_btn = gr.Button("Get Recommendations", variant="primary")
|
120 |
+
|
121 |
+
with gr.Row():
|
122 |
+
output = gr.JSON(label="Recommended Assessments")
|
123 |
+
|
124 |
+
submit_btn.click(fn=recommend, inputs=job_description, outputs=output)
|
125 |
+
|
126 |
+
# Add path to access Gradio directly at root
|
127 |
@app.get("/")
|
128 |
async def root():
|
129 |
+
return RedirectResponse(url="/")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
|
131 |
+
# For Hugging Face Spaces deployment with Gradio SDK
|
132 |
+
app = gr.mount_gradio_app(app, demo)
|
|
|
|
|
133 |
|
134 |
+
# If running standalone (not through Hugging Face), use this instead
|
135 |
if __name__ == "__main__":
|
136 |
import uvicorn
|
137 |
+
# Uncomment the line below if running locally not on HF
|
138 |
+
# uvicorn.run(app, host="0.0.0.0", port=7860)
|
139 |
+
# Use this for Hugging Face deployment
|
140 |
+
demo.launch()
|