Skip to content

Commit e276bbb

Browse files
Merge branch 'main' of github.com:lokeshwaran100/neploy
2 parents 12daa83 + bb474cf commit e276bbb

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

src/backend/neploy-build-python/ml-code-optimiser.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# comment # This code first reads the Python smart contract script from a file. Then, it uses the model to predict the suggested improvements for the smart contract code. Finally, it prints the suggested improvements
2-
31
import numpy as np
42
import pandas as pd
53
from sklearn.model_selection import train_test_split
@@ -38,17 +36,18 @@
3836
with open("test.py", "r") as f:
3937
code = f.read()
4038

41-
# Predict the improvement suggestions for the code
42-
new_code_vectorized = vectorizer.transform([code])
43-
prediction = model.predict(new_code_vectorized)[0]
44-
45-
# Print the improvement suggestions
46-
if prediction == "optimize":
47-
print("The code needs to be optimized.")
48-
print("Suggested improvements:")
49-
for suggestion in model.predict_proba(new_code_vectorized)[0]:
50-
print(f"* {suggestion}")
51-
else:
52-
print("The code is fine.")
53-
54-
39+
# Split the code into lines
40+
lines = code.split("\n")
41+
42+
# Predict the improvement suggestions for each line of code
43+
for i, line in enumerate(lines):
44+
new_code_vectorized = vectorizer.transform([line])
45+
prediction = model.predict(new_code_vectorized)[0]
46+
47+
# Print the improvement suggestions
48+
if prediction == "optimize":
49+
print("Line {}: The following are the suggested optimization snippets:".format(i + 1))
50+
for snippet in model.predict_proba(new_code_vectorized)[0]:
51+
print(snippet)
52+
else:
53+
print("Line {}: The code is fine.".format(i + 1))

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy