Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -66,9 +66,16 @@ def generate_code(data: RequestData):
|
|
66 |
generated_text = tokenizer.decode(output_ids[0][input_ids.shape[-1]:], skip_special_tokens=True)
|
67 |
|
68 |
# Only return JavaScript function — no extra text
|
69 |
-
|
70 |
-
|
71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
from fastapi.responses import PlainTextResponse
|
73 |
return PlainTextResponse(clean_output)
|
74 |
|
|
|
|
66 |
generated_text = tokenizer.decode(output_ids[0][input_ids.shape[-1]:], skip_special_tokens=True)
|
67 |
|
68 |
# Only return JavaScript function — no extra text
|
69 |
+
# Extract only the JavaScript function that ends with return row;
|
70 |
+
match = re.search(r"function\s+transform\s*\([^)]*\)\s*{[^}]*return row;\s*}", generated_text, re.DOTALL)
|
71 |
+
if match:
|
72 |
+
clean_output = match.group(0).strip()
|
73 |
+
else:
|
74 |
+
# fallback: try to grab only up to "return row;"
|
75 |
+
fallback = generated_text.split("return row;")[0] + "return row;"
|
76 |
+
clean_output = fallback.strip()
|
77 |
+
|
78 |
from fastapi.responses import PlainTextResponse
|
79 |
return PlainTextResponse(clean_output)
|
80 |
|
81 |
+
|