Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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 |
-
#
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
else:
|
| 113 |
-
return "Error: Unable to extract the
|
| 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(
|