Update app.py
Browse files
app.py
CHANGED
|
@@ -19,38 +19,32 @@ app.add_middleware(
|
|
| 19 |
|
| 20 |
@app.post("/api/humanize")
|
| 21 |
async def generate_humanized_text(request: Request):
|
| 22 |
-
# 1. Read
|
| 23 |
try:
|
| 24 |
body = await request.json()
|
| 25 |
-
|
| 26 |
-
except Exception:
|
| 27 |
raise HTTPException(status_code=400, detail="Invalid JSON")
|
| 28 |
|
| 29 |
-
# 2. Extract
|
| 30 |
text = body.get("text")
|
| 31 |
-
if not
|
| 32 |
-
raise HTTPException(status_code=400, detail="
|
| 33 |
|
| 34 |
-
# 3. Build prompt
|
| 35 |
-
prompt =
|
| 36 |
-
"Humanize the following text, making it sound natural and engaging:\n\n"
|
| 37 |
-
f"{text}"
|
| 38 |
-
)
|
| 39 |
|
|
|
|
| 40 |
try:
|
| 41 |
response = client.text_generation(
|
| 42 |
prompt,
|
| 43 |
max_new_tokens=512,
|
| 44 |
temperature=0.7,
|
| 45 |
-
top_p=0.9,
|
| 46 |
-
repetition_penalty=1.1,
|
| 47 |
)
|
| 48 |
except Exception as e:
|
| 49 |
-
|
| 50 |
-
raise HTTPException(status_code=500, detail=f"HF error: {e}")
|
| 51 |
|
| 52 |
return {"result": response}
|
| 53 |
|
| 54 |
@app.get("/")
|
| 55 |
-
def
|
| 56 |
-
return {"status": "ok"
|
|
|
|
| 19 |
|
| 20 |
@app.post("/api/humanize")
|
| 21 |
async def generate_humanized_text(request: Request):
|
| 22 |
+
# 1. Read JSON body
|
| 23 |
try:
|
| 24 |
body = await request.json()
|
| 25 |
+
except:
|
|
|
|
| 26 |
raise HTTPException(status_code=400, detail="Invalid JSON")
|
| 27 |
|
| 28 |
+
# 2. Extract field
|
| 29 |
text = body.get("text")
|
| 30 |
+
if not text:
|
| 31 |
+
raise HTTPException(status_code=400, detail="Missing 'text' field")
|
| 32 |
|
| 33 |
+
# 3. Build prompt
|
| 34 |
+
prompt = f"Humanize the following text:\n\n{text}"
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
+
# 4. Generate output
|
| 37 |
try:
|
| 38 |
response = client.text_generation(
|
| 39 |
prompt,
|
| 40 |
max_new_tokens=512,
|
| 41 |
temperature=0.7,
|
|
|
|
|
|
|
| 42 |
)
|
| 43 |
except Exception as e:
|
| 44 |
+
raise HTTPException(status_code=500, detail=str(e))
|
|
|
|
| 45 |
|
| 46 |
return {"result": response}
|
| 47 |
|
| 48 |
@app.get("/")
|
| 49 |
+
def health():
|
| 50 |
+
return {"status": "ok"}
|