Spaces:
Sleeping
Sleeping
Update server.py
Browse files
server.py
CHANGED
|
@@ -1,7 +1,8 @@
|
|
| 1 |
import sys
|
| 2 |
from flask import Flask, request, jsonify
|
| 3 |
from flask_cors import CORS
|
| 4 |
-
|
|
|
|
| 5 |
|
| 6 |
# --- 1. Initialize Flask App ---
|
| 7 |
app = Flask(__name__)
|
|
@@ -67,12 +68,9 @@ def optimize_code():
|
|
| 67 |
|
| 68 |
full_response = opt_result[0]['generated_text']
|
| 69 |
|
| 70 |
-
# Clean up
|
| 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 |
|
|
|
|
| 1 |
import sys
|
| 2 |
from flask import Flask, request, jsonify
|
| 3 |
from flask_cors import CORS
|
| 4 |
+
# We need AutoTokenizer for the "stop" button
|
| 5 |
+
from transformers import pipeline, AutoTokenizer
|
| 6 |
|
| 7 |
# --- 1. Initialize Flask App ---
|
| 8 |
app = Flask(__name__)
|
|
|
|
| 68 |
|
| 69 |
full_response = opt_result[0]['generated_text']
|
| 70 |
|
| 71 |
+
# Clean up the Llama chat response
|
|
|
|
| 72 |
if "<|assistant|>" in full_response:
|
| 73 |
clean_optimization = full_response.split("<|assistant|>")[-1].strip()
|
|
|
|
|
|
|
| 74 |
else:
|
| 75 |
clean_optimization = full_response
|
| 76 |
|