ziyan14 commited on
Commit
324d5ea
·
verified ·
1 Parent(s): bb55128

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -34
app.py CHANGED
@@ -11,50 +11,53 @@ import re
11
  import ast
12
  import time
13
  from collections import deque
14
- from dotenv import load_dotenv
15
  import gradio as gr
16
  from google import genai
17
 
18
- load_dotenv()
19
-
20
 
21
  # ---------------------------------------------------------------------------
22
  # MODULE 3 — Pre-processing Module
23
  # ---------------------------------------------------------------------------
24
- def pre_processing(description, code):
25
- build_prompt = f"""
26
- #ROLE
27
- You are a Python code reviewer. Your goal is to determine if the provided Python code strictly complies with the requirements mentioned by the user.
28
-
29
- #CONTEXT
30
- Developers may create code that does not entirely meet the specified requirements. You will examine the relationship between a natural-language description and a Python code sample and create a structured evaluation report.
31
-
32
- #INPUT DATA
33
- Description: {description}
34
- Code: ```python
35
- {code}
 
 
 
 
36
  ```
37
-
38
- #TASK
39
- 1. Carefully read the requirements description.
40
- 2. Examine each line of the Python code.
41
  3. Determine whether the code fulfils ALL requirements stated in the description.
42
- 4. Estimate the accuracy in percentages to assess how accurately the code matches the description.
43
- 5. List specific requirements that are either absent or incorrectly applied.
44
- 6. Base your evaluation solely on static code analysis and logical reasoning.
45
-
46
- #CONSTRAINTS
47
- 1. Do not execute the code.
48
- 2. The output must be in the specified format.
49
- 3. The output should be clear and concise.
50
-
51
- #OUTPUT FORMAT (to be strictly followed without any changes)
52
- Result: either "Pass" or "Fail" (Pass if the code is functional and matches the description, Fail if it has bugs or doesn't match).
53
- Accuracy: an integer from 0 to 100 representing how well the code matches the description and is bug-free.
54
- Review: a short prose explanation of the result (e.g. "Code correctly handles all described requirements including edge cases.").
55
- Issues: The value should be a single string containing a numbered list. For each item, include the severity (Error, Warning, or Info) followed by a dash and description of the issue (e.g. "Missing type hints on function signature"). List each issue on a new line starting with a number. Use newline characters (\n) to separate each line.
 
 
56
  ...
57
-
 
58
  """
59
  return prompt
60
 
 
11
  import ast
12
  import time
13
  from collections import deque
 
14
  import gradio as gr
15
  from google import genai
16
 
 
 
17
 
18
  # ---------------------------------------------------------------------------
19
  # MODULE 3 — Pre-processing Module
20
  # ---------------------------------------------------------------------------
21
+ def build_prompt(description: str, code: str) -> str:
22
+ prompt = f"""<start_of_turn>user
23
+ ### ROLE
24
+ You are an expert Python code reviewer. Your sole task is to determine whether the
25
+ provided Python code correctly implements the behaviour described in the user's
26
+ requirements description.
27
+ ### CONTEXT
28
+ Developers sometimes write code that does not fully satisfy the requirements they
29
+ were given. You will analyse the semantic relationship between a natural-language
30
+ description and a Python code snippet, then produce a structured evaluation report.
31
+ ### INPUT DATA
32
+ **Requirements Description:**
33
+ {description.strip()}
34
+ **Python Code:**
35
+ ```python
36
+ {code.strip()}
37
  ```
38
+ ### TASK
39
+ 1. Read the requirements description carefully.
40
+ 2. Analyse the Python code line by line.
 
41
  3. Determine whether the code fulfils ALL requirements stated in the description.
42
+ 4. Estimate an accuracy percentage (0–100) reflecting how completely the code
43
+ matches the description.
44
+ 5. List any specific requirements that are missing or incorrectly implemented.
45
+ ### CONSTRAINTS
46
+ - Do NOT execute the code.
47
+ - Base your evaluation solely on static code analysis and logical reasoning.
48
+ - Keep feedback concise, clear, and actionable.
49
+ - Your response MUST follow the output format exactly.
50
+ ### OUTPUT FORMAT
51
+ Respond only with the following structure no extra text before or after:
52
+ RESULT: <PASS or FAIL>
53
+ ACCURACY: <integer 0-100>%
54
+ SUMMARY: <one sentence overall assessment>
55
+ ISSUES:
56
+ - <issue 1, or "None" if code fully matches the description>
57
+ - <issue 2>
58
  ...
59
+ <end_of_turn>
60
+ <start_of_turn>model
61
  """
62
  return prompt
63