File tree Expand file tree Collapse file tree 1 file changed +15
-18
lines changed
src/backend/neploy-build-python Expand file tree Collapse file tree 1 file changed +15
-18
lines changed Original file line number Diff line number Diff line change 38
38
with open ("test.py" , "r" ) as f :
39
39
code = f .read ()
40
40
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
-
49
- # Get the top 3 suggestions
50
- top_3_suggestions = model .predict_proba (new_code_vectorized ).argsort ()[- 3 :][::- 1 ]
51
-
52
- # Print the suggestions
53
- for index in top_3_suggestions :
54
- snippet , probability = model .predict_proba (new_code_vectorized )[0 ][index ]
55
- print (f"{ index + 1 } : { snippet } ({ probability * 100 :.2f} %)" )
56
- else :
57
- print ("The code is fine." )
58
-
41
+ # Split the code into lines
42
+ lines = code .split ("\n " )
43
+
44
+ # Predict the improvement suggestions for each line of code
45
+ for line in lines :
46
+ new_code_vectorized = vectorizer .transform ([line ])
47
+ prediction = model .predict (new_code_vectorized )[0 ]
48
+
49
+ # Print the improvement suggestions
50
+ if prediction == "optimize" :
51
+ print ("The following are the suggested optimization snippets for line {}:" .format (line ))
52
+ for snippet in model .predict_proba (new_code_vectorized )[0 ]:
53
+ print (snippet )
54
+ else :
55
+ print ("The code in line {} is fine." .format (line ))
You can’t perform that action at this time.
0 commit comments