Spaces:
Sleeping
Sleeping
Update server.py
Browse files
server.py
CHANGED
|
@@ -21,7 +21,7 @@ try:
|
|
| 21 |
print(f"Loading {model_name} model...")
|
| 22 |
hf_task = 'text-generation'
|
| 23 |
|
| 24 |
-
# --- THIS IS THE FIX ---
|
| 25 |
# 1. We load the tokenizer so we know its "stop" token
|
| 26 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 27 |
|
|
@@ -68,8 +68,11 @@ def optimize_code():
|
|
| 68 |
full_response = opt_result[0]['generated_text']
|
| 69 |
|
| 70 |
# Clean up: We only want the part AFTER "Optimized Code:"
|
| 71 |
-
|
| 72 |
-
|
|
|
|
|
|
|
|
|
|
| 73 |
else:
|
| 74 |
clean_optimization = full_response
|
| 75 |
|
|
|
|
| 21 |
print(f"Loading {model_name} model...")
|
| 22 |
hf_task = 'text-generation'
|
| 23 |
|
| 24 |
+
# --- THIS IS THE "STOP" TOKEN FIX ---
|
| 25 |
# 1. We load the tokenizer so we know its "stop" token
|
| 26 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 27 |
|
|
|
|
| 68 |
full_response = opt_result[0]['generated_text']
|
| 69 |
|
| 70 |
# Clean up: We only want the part AFTER "Optimized Code:"
|
| 71 |
+
# We must clean the *original* prompt, not the *new* one.
|
| 72 |
+
if "<|assistant|>" in full_response:
|
| 73 |
+
clean_optimization = full_response.split("<|assistant|>")[-1].strip()
|
| 74 |
+
elif "Optimized Code:" in full_response:
|
| 75 |
+
clean_optimization = full_response.split("Optimized Code:")[-1].strip()
|
| 76 |
else:
|
| 77 |
clean_optimization = full_response
|
| 78 |
|