Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,6 +4,10 @@ import json
|
|
| 4 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 5 |
from peft import PeftModel, PeftConfig
|
| 6 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
# --- Configuration ---
|
| 9 |
# Base model: The instruction-tuned version of Llama 3.1 8B.
|
|
@@ -166,6 +170,36 @@ Generate the matching analysis as a JSON object:
|
|
| 166 |
return f"An unexpected error occurred during processing: {e}"
|
| 167 |
|
| 168 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
# --- Gradio Interface Setup ---
|
| 170 |
|
| 171 |
# Example data for user convenience
|
|
@@ -249,6 +283,9 @@ with gr.Blocks(title="CV & Job Matcher (Mployd Alpha Version)") as demo:
|
|
| 249 |
outputs=output_display
|
| 250 |
)
|
| 251 |
|
|
|
|
|
|
|
|
|
|
| 252 |
# Launch the Gradio app
|
| 253 |
if __name__ == "__main__":
|
| 254 |
load_model() # Ensure model loading is called before demo launch
|
|
|
|
| 4 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 5 |
from peft import PeftModel, PeftConfig
|
| 6 |
import os
|
| 7 |
+
from fastapi import FastAPI
|
| 8 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 9 |
+
from pydantic import BaseModel
|
| 10 |
+
|
| 11 |
|
| 12 |
# --- Configuration ---
|
| 13 |
# Base model: The instruction-tuned version of Llama 3.1 8B.
|
|
|
|
| 170 |
return f"An unexpected error occurred during processing: {e}"
|
| 171 |
|
| 172 |
|
| 173 |
+
# --- endpoint
|
| 174 |
+
|
| 175 |
+
fastapi_app = FastAPI()
|
| 176 |
+
|
| 177 |
+
# Allow cross-origin requests (optional but helpful)
|
| 178 |
+
fastapi_app.add_middleware(
|
| 179 |
+
CORSMiddleware,
|
| 180 |
+
allow_origins=["*"],
|
| 181 |
+
allow_methods=["*"],
|
| 182 |
+
allow_headers=["*"],
|
| 183 |
+
)
|
| 184 |
+
|
| 185 |
+
# Request body schema
|
| 186 |
+
class PredictRequest(BaseModel):
|
| 187 |
+
cv: str
|
| 188 |
+
jd: str
|
| 189 |
+
|
| 190 |
+
@fastapi_app.post("/predict")
|
| 191 |
+
def predict_api(payload: PredictRequest):
|
| 192 |
+
# Ensure the model is loaded
|
| 193 |
+
load_model()
|
| 194 |
+
result = match_cv_jd(payload.cv, payload.jd)
|
| 195 |
+
|
| 196 |
+
# Return already-formatted JSON string — parse it first
|
| 197 |
+
try:
|
| 198 |
+
return json.loads(result)
|
| 199 |
+
except:
|
| 200 |
+
return {"error": "Model returned non-JSON response", "raw": result}
|
| 201 |
+
|
| 202 |
+
|
| 203 |
# --- Gradio Interface Setup ---
|
| 204 |
|
| 205 |
# Example data for user convenience
|
|
|
|
| 283 |
outputs=output_display
|
| 284 |
)
|
| 285 |
|
| 286 |
+
|
| 287 |
+
demo.app = fastapi_app
|
| 288 |
+
|
| 289 |
# Launch the Gradio app
|
| 290 |
if __name__ == "__main__":
|
| 291 |
load_model() # Ensure model loading is called before demo launch
|