rootxhacker commited on
Commit
2cf6bfb
1 Parent(s): bbc12dc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -12
app.py CHANGED
@@ -53,18 +53,18 @@ def get_completion(query, model, tokenizer):
53
 
54
  @spaces.GPU()
55
  def code_review(code_to_analyze):
56
- few_shot_prompt = """Review the following code for security vulnerabilities, logic flaws, and potential improvements:
57
 
58
  ```php
59
- function authenticateUser($username, $password) {
60
  $conn = new mysqli("localhost", "user", "password", "database");
61
  $query = "SELECT * FROM users WHERE username = '$username' AND password = '$password'";
62
  $result = $conn->query($query);
63
- if ($result->num_rows > 0) {
64
  return true;
65
- }
66
  return false;
67
- }
68
  ```
69
 
70
  1. Understanding of the code:
@@ -103,14 +103,20 @@ Start each section with its number and title."""
103
 
104
  full_response = get_completion(few_shot_prompt, model, tokenizer)
105
 
106
- # Extract only the part of the response after the input code
107
- start_marker = f"Now, review the following code using the same approach:\n\n{code_to_analyze}\n\n"
108
- start_index = full_response.find(start_marker)
109
- if start_index != -1:
110
- relevant_response = full_response[start_index + len(start_marker):].strip()
111
- return relevant_response
 
 
 
 
 
 
112
  else:
113
- return "Error: Unable to extract the relevant part of the AI's response."
114
 
115
  # Create Gradio interface
116
  iface = gr.Interface(
 
53
 
54
  @spaces.GPU()
55
  def code_review(code_to_analyze):
56
+ few_shot_prompt = f"""Review the following code for security vulnerabilities, logic flaws, and potential improvements:
57
 
58
  ```php
59
+ function authenticateUser($username, $password) {{
60
  $conn = new mysqli("localhost", "user", "password", "database");
61
  $query = "SELECT * FROM users WHERE username = '$username' AND password = '$password'";
62
  $result = $conn->query($query);
63
+ if ($result->num_rows > 0) {{
64
  return true;
65
+ }}
66
  return false;
67
+ }}
68
  ```
69
 
70
  1. Understanding of the code:
 
103
 
104
  full_response = get_completion(few_shot_prompt, model, tokenizer)
105
 
106
+ # Find the start of the AI's response (after the input code)
107
+ response_start = full_response.find(code_to_analyze)
108
+ if response_start != -1:
109
+ response_start += len(code_to_analyze)
110
+ ai_response = full_response[response_start:].strip()
111
+
112
+ # Remove any leading text before the first numbered section
113
+ first_section = ai_response.find("1.")
114
+ if first_section != -1:
115
+ ai_response = ai_response[first_section:]
116
+
117
+ return ai_response
118
  else:
119
+ return "Error: Unable to extract the AI's response. Here's the full output:\n\n" + full_response
120
 
121
  # Create Gradio interface
122
  iface = gr.Interface(