Update app.py
Browse files
app.py
CHANGED
@@ -51,7 +51,6 @@ Content: "{content}"
|
|
51 |
log.info(f"🧠 Inferência iniciada para: {title}")
|
52 |
start_time = time.time()
|
53 |
|
54 |
-
# Tokenização + attention mask
|
55 |
inputs = tokenizer(
|
56 |
prompt,
|
57 |
return_tensors="pt",
|
@@ -68,8 +67,8 @@ Content: "{content}"
|
|
68 |
attention_mask=attention_mask,
|
69 |
max_new_tokens=100,
|
70 |
temperature=1.0,
|
71 |
-
do_sample=False,
|
72 |
-
top_k=50,
|
73 |
no_repeat_ngram_size=2,
|
74 |
num_beams=1,
|
75 |
eos_token_id=tokenizer.eos_token_id,
|
@@ -90,7 +89,7 @@ Content: "{content}"
|
|
90 |
return json_result
|
91 |
else:
|
92 |
log.warning("⚠️ Falha ao extrair JSON.")
|
93 |
-
|
94 |
|
95 |
# -------- API --------
|
96 |
@app.get("/filter")
|
@@ -102,9 +101,8 @@ def get_filter(
|
|
102 |
json_output = infer_filter(title, content)
|
103 |
import json
|
104 |
return json.loads(json_output)
|
105 |
-
except
|
106 |
-
|
107 |
-
return {"raw_output": json_output}
|
108 |
except Exception as e:
|
109 |
log.exception("❌ Erro inesperado:")
|
110 |
-
raise HTTPException(status_code=
|
|
|
51 |
log.info(f"🧠 Inferência iniciada para: {title}")
|
52 |
start_time = time.time()
|
53 |
|
|
|
54 |
inputs = tokenizer(
|
55 |
prompt,
|
56 |
return_tensors="pt",
|
|
|
67 |
attention_mask=attention_mask,
|
68 |
max_new_tokens=100,
|
69 |
temperature=1.0,
|
70 |
+
do_sample=False,
|
71 |
+
top_k=50,
|
72 |
no_repeat_ngram_size=2,
|
73 |
num_beams=1,
|
74 |
eos_token_id=tokenizer.eos_token_id,
|
|
|
89 |
return json_result
|
90 |
else:
|
91 |
log.warning("⚠️ Falha ao extrair JSON.")
|
92 |
+
raise HTTPException(status_code=404, detail="Unable to extract JSON from model output.")
|
93 |
|
94 |
# -------- API --------
|
95 |
@app.get("/filter")
|
|
|
101 |
json_output = infer_filter(title, content)
|
102 |
import json
|
103 |
return json.loads(json_output)
|
104 |
+
except HTTPException as he:
|
105 |
+
raise he # já tratado
|
|
|
106 |
except Exception as e:
|
107 |
log.exception("❌ Erro inesperado:")
|
108 |
+
raise HTTPException(status_code=404, detail="Invalid or malformed JSON output from model.")
|