Update server.py
Browse files
server.py
CHANGED
|
@@ -55,7 +55,7 @@ print(f"β Image transform defined (size: {CONFIG['image_size']}x{CONFIG['image
|
|
| 55 |
def preprocess_image(image_path: str) -> torch.Tensor:
|
| 56 |
"""Load and preprocess image."""
|
| 57 |
image = Image.open(image_path).convert('RGB')
|
| 58 |
-
return transform(image)
|
| 59 |
|
| 60 |
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 61 |
# ARCHITECTURE 1 β CoAtNet Encoder (shared by all three models)
|
|
@@ -434,7 +434,7 @@ async def sft_inference(file: UploadFile = File(...)):
|
|
| 434 |
|
| 435 |
try:
|
| 436 |
# Use file path preprocessing (exact Colab match)
|
| 437 |
-
tensor = preprocess_image(temp_path)
|
| 438 |
report = sft_model.generate_reports(tensor)[0]
|
| 439 |
print(f"[SFT] Generated: {report}")
|
| 440 |
return {"report": report[:81]}
|
|
@@ -458,7 +458,7 @@ async def reward_inference(file: UploadFile = File(...)):
|
|
| 458 |
|
| 459 |
try:
|
| 460 |
# Use file path preprocessing (exact Colab match)
|
| 461 |
-
tensor = preprocess_image(temp_path)
|
| 462 |
# First get the SFT report to score
|
| 463 |
sft_report = sft_model.generate_reports(tensor)[0]
|
| 464 |
print(f"[REWARD] Scoring SFT report: {sft_report}")
|
|
@@ -528,7 +528,7 @@ async def ppo_inference(file: UploadFile = File(...)):
|
|
| 528 |
|
| 529 |
try:
|
| 530 |
# Use file path preprocessing (exact Colab match)
|
| 531 |
-
tensor = preprocess_image(temp_path)
|
| 532 |
report = ppo_model.generate_reports(tensor)[0]
|
| 533 |
print(f"[PPO] Generated: {report}")
|
| 534 |
return {"report": report}
|
|
|
|
| 55 |
def preprocess_image(image_path: str) -> torch.Tensor:
|
| 56 |
"""Load and preprocess image."""
|
| 57 |
image = Image.open(image_path).convert('RGB')
|
| 58 |
+
return transform(image)
|
| 59 |
|
| 60 |
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 61 |
# ARCHITECTURE 1 β CoAtNet Encoder (shared by all three models)
|
|
|
|
| 434 |
|
| 435 |
try:
|
| 436 |
# Use file path preprocessing (exact Colab match)
|
| 437 |
+
tensor = preprocess_image(temp_path).unsqueeze(0).to(device)
|
| 438 |
report = sft_model.generate_reports(tensor)[0]
|
| 439 |
print(f"[SFT] Generated: {report}")
|
| 440 |
return {"report": report[:81]}
|
|
|
|
| 458 |
|
| 459 |
try:
|
| 460 |
# Use file path preprocessing (exact Colab match)
|
| 461 |
+
tensor = preprocess_image(temp_path).unsqueeze(0).to(device)
|
| 462 |
# First get the SFT report to score
|
| 463 |
sft_report = sft_model.generate_reports(tensor)[0]
|
| 464 |
print(f"[REWARD] Scoring SFT report: {sft_report}")
|
|
|
|
| 528 |
|
| 529 |
try:
|
| 530 |
# Use file path preprocessing (exact Colab match)
|
| 531 |
+
tensor = preprocess_image(temp_path).unsqueeze(0).to(device)
|
| 532 |
report = ppo_model.generate_reports(tensor)[0]
|
| 533 |
print(f"[PPO] Generated: {report}")
|
| 534 |
return {"report": report}
|