Changes
Browse files- app.py +5 -1
- gemini.py +2 -2
- handler.py +17 -0
- prompts.py +132 -5
app.py
CHANGED
@@ -19,7 +19,7 @@ def main():
|
|
19 |
with col2:
|
20 |
# Radio buttons for analysis type
|
21 |
analysis_type = st.radio("Choose analysis type:",
|
22 |
-
("Code review", "Code refinement","Documentation", "
|
23 |
|
24 |
# Submit button
|
25 |
if st.button("Submit"):
|
@@ -40,6 +40,10 @@ def main():
|
|
40 |
res=generate_documentation(code, prompt)
|
41 |
#st.text_area(label="Result",value=res, height=300)
|
42 |
st.markdown(res)
|
|
|
|
|
|
|
|
|
43 |
|
44 |
st.success(f"Code analysis for {analysis_type} submitted successfully!")
|
45 |
|
|
|
19 |
with col2:
|
20 |
# Radio buttons for analysis type
|
21 |
analysis_type = st.radio("Choose analysis type:",
|
22 |
+
("Code review", "Code refinement","Documentation", "Resume Writer"))
|
23 |
|
24 |
# Submit button
|
25 |
if st.button("Submit"):
|
|
|
40 |
res=generate_documentation(code, prompt)
|
41 |
#st.text_area(label="Result",value=res, height=300)
|
42 |
st.markdown(res)
|
43 |
+
elif analysis_type == "Resume Writer":
|
44 |
+
res=resume_writer(code, prompt)
|
45 |
+
#st.text_area(label="Result",value=res, height=300)
|
46 |
+
st.markdown(res)
|
47 |
|
48 |
st.success(f"Code analysis for {analysis_type} submitted successfully!")
|
49 |
|
gemini.py
CHANGED
@@ -23,13 +23,13 @@ class GeminiModel:
|
|
23 |
"""
|
24 |
|
25 |
def __init__(self,
|
26 |
-
|
27 |
):
|
28 |
|
29 |
|
30 |
load_dotenv()
|
31 |
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
32 |
-
self.model = genai.GenerativeModel(
|
33 |
|
34 |
|
35 |
def execute(self, prompt: str) -> str:
|
|
|
23 |
"""
|
24 |
|
25 |
def __init__(self,
|
26 |
+
model_name: Optional[str] = 'gemini-pro',
|
27 |
):
|
28 |
|
29 |
|
30 |
load_dotenv()
|
31 |
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
32 |
+
self.model = genai.GenerativeModel(model_name) # type: ignore
|
33 |
|
34 |
|
35 |
def execute(self, prompt: str) -> str:
|
handler.py
CHANGED
@@ -55,6 +55,23 @@ def generate_documentation(code,c_prompt):
|
|
55 |
|
56 |
return res
|
57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
class InvalidCodeException(Exception):
|
59 |
pass
|
60 |
|
|
|
55 |
|
56 |
return res
|
57 |
|
58 |
+
def resume_writer(code,c_prompt):
|
59 |
+
|
60 |
+
if code is None or len(code) < 5 or code.isspace():
|
61 |
+
raise InvalidCodeException("No code provided")
|
62 |
+
|
63 |
+
if c_prompt is not None and len(c_prompt) > 30:
|
64 |
+
prompt = custom_review_prompt(code.strip(), c_prompt.strip())
|
65 |
+
else:
|
66 |
+
prompt = resume_prompt(code.strip())
|
67 |
+
|
68 |
+
model = gemini.GeminiModel()
|
69 |
+
try:
|
70 |
+
res = model.execute(prompt)
|
71 |
+
except Exception as e:
|
72 |
+
raise CodeReviewException(str(e))
|
73 |
+
|
74 |
+
return res
|
75 |
class InvalidCodeException(Exception):
|
76 |
pass
|
77 |
|
prompts.py
CHANGED
@@ -170,13 +170,140 @@ A refined and optimized version of the code.
|
|
170 |
def default_doc_prompt(code):
|
171 |
|
172 |
|
173 |
-
prompt= f""""
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
178 |
return prompt
|
179 |
|
|
|
|
|
180 |
def validation_prompt(code, guidelines=None):
|
181 |
prompt=f"""Check if the below input contains code snippets or not. Return only Yes or NO and nothing else.
|
182 |
Input: {code}
|
|
|
170 |
def default_doc_prompt(code):
|
171 |
|
172 |
|
173 |
+
prompt= f""""**Role:** Technical Writer
|
174 |
+
|
175 |
+
**Task:** Generate formal documentation for the provided Python code.
|
176 |
+
|
177 |
+
**Context:** The provided Python code snippet requires comprehensive formal documentation. This documentation should clearly explain the code's functionality and purpose, including all relevant details expected in formal documentation.
|
178 |
+
|
179 |
+
**Instructions:**
|
180 |
+
* Take a deep breath and thoroughly analyze the provided Python code.
|
181 |
+
* Understand the code's logic, flow, and intended functionality.
|
182 |
+
* Generate formal documentation that is clear, concise, and informative.
|
183 |
+
* Explain the code's purpose, functionality, and any relevant details.
|
184 |
+
* Use proper formatting, structure, and language appropriate for formal documentation.
|
185 |
+
* Ensure the documentation is comprehensive and addresses all aspects of the code.
|
186 |
+
|
187 |
+
**Guidelines:**
|
188 |
+
* Follow the guidelines for writing formal documentation.
|
189 |
+
* Use clear and concise language.
|
190 |
+
* Avoid ambiguity and ensure the documentation is easy to understand.
|
191 |
+
* Use proper grammar and punctuation.
|
192 |
+
* Structure the documentation logically and use headings and subheadings for clarity.
|
193 |
+
* Include relevant comments and explanations within the code itself.
|
194 |
+
|
195 |
+
**Examples:**
|
196 |
+
* Provide examples of how the code can be used.
|
197 |
+
* Include code snippets to illustrate specific functionalities.
|
198 |
+
* Use diagrams or flowcharts to visualize complex logic.
|
199 |
+
|
200 |
+
**Steps:**
|
201 |
+
1. Analyze the Python code and understand its functionality.
|
202 |
+
2. Gather all relevant information about the code, including its purpose, inputs, outputs, and any dependencies.
|
203 |
+
3. Structure the documentation logically, using headings and subheadings to organize the information.
|
204 |
+
4. Write clear and concise explanations of the code's functionality.
|
205 |
+
5. Include relevant examples and code snippets to illustrate the code's usage.
|
206 |
+
6. Proofread and edit the documentation carefully to ensure accuracy and clarity.
|
207 |
+
|
208 |
+
**Goal:** Generate comprehensive and accurate formal documentation for the provided Python code in one iteration.
|
209 |
+
|
210 |
+
**Additional Notes:**
|
211 |
+
* Consider using a documentation generator tool to assist with the formatting and structure of the documentation.
|
212 |
+
* Review the documentation with a technical expert to ensure its accuracy and completeness.
|
213 |
+
* If further clarification is needed, feel free to ask for additional information or context regarding the code.
|
214 |
+
|
215 |
+
**Code:** {code}
|
216 |
+
"""
|
217 |
+
|
218 |
+
promptt = f"""**Instruction**: As an adept programmer, meticulously dissect the given code snippet and meticulously document it in accordance with the provided Output Format. If you encounter any functionalities or concepts you're uncertain about, provide the best possible descriptions and indicate areas necessitating further investigation. Avoid conjectures and ensure explanations are substantiated. If certain sections of the **Output Format** aren't applicable, simply exclude them from the output.
|
219 |
+
|
220 |
+
**Output Format**:
|
221 |
+
##Dependencies:
|
222 |
+
1. Frameworks/Libraries:
|
223 |
+
List any external libraries, frameworks, or modules required by the code along with a succinct description for each.
|
224 |
+
2. Cloud Services:
|
225 |
+
Enumerate all cloud services invoked within the code, providing a concise description for each service's purpose or functionality in one line.
|
226 |
+
|
227 |
+
## Functions used:
|
228 |
+
Present a clear and organized table showcasing the name of each function, along with its corresponding input/arguments, expected output, and the function's purpose. The table should be formatted neatly for easy readability. All "|" should fall on same line. Use the following column headings:
|
229 |
+
| Function Name | Input/Arguments | Output | Purpose |
|
230 |
+
|
231 |
+
##Steps Conducted:
|
232 |
+
Translate the developer's actions for each function into a detailed and easily readable format. Additionally, include a flow diagram to illustrate the code's flow step by step.
|
233 |
+
|
234 |
+
##Suggestions for Improvement:
|
235 |
+
Offer recommendations for enhancing the code, potential optimizations, or logic enhancements. Provide a code snippet for each suggestion, avoiding unnecessary assumptions.
|
236 |
+
|
237 |
+
Task: Showcase your proficiency by creating a comprehensive documentation set for the provided code snippet. Adhere strictly to the outlined Output Format.
|
238 |
+
**Code**: {code}
|
239 |
+
|
240 |
+
"""
|
241 |
+
return prompt
|
242 |
+
|
243 |
+
def resume_prompt(details, guidelines=None):
|
244 |
+
prompt=f"""**Role:** Resume Writer
|
245 |
+
|
246 |
+
**Task:** Generate a well-structured, impactful resume brief based on the provided candidate's resume.
|
247 |
+
|
248 |
+
**Context:** You are a professional resume writer with extensive experience in crafting compelling resumes that effectively showcase candidates' skills and experience. You have access to the candidate's resume and are familiar with industry best practices for resume writing.
|
249 |
+
|
250 |
+
**Instructions:**
|
251 |
+
|
252 |
+
* Take a deep breath and thoroughly analyze the candidate's resume.
|
253 |
+
* Identify the most relevant and impactful information that aligns with the target job description.
|
254 |
+
* Use a formal and impactful tone while highlighting the candidate's key strengths and accomplishments.
|
255 |
+
* Structure the resume brief in a clear and concise manner, using bullet points and headings for easy readability.
|
256 |
+
* Ensure that the resume brief is tailored to the specific job the candidate is applying for.
|
257 |
+
|
258 |
+
**Guidelines:**
|
259 |
+
|
260 |
+
* Follow industry best practices for resume writing.
|
261 |
+
* Use clear and concise language.
|
262 |
+
* Avoid jargon and technical terms that the hiring manager may not understand.
|
263 |
+
* Proofread carefully for any errors in grammar or spelling.
|
264 |
+
|
265 |
+
**Example:**
|
266 |
+
|
267 |
+
**Candidate:** John Doe
|
268 |
+
|
269 |
+
**Target Job:** Software Engineer
|
270 |
+
|
271 |
+
**Resume Brief:**
|
272 |
+
|
273 |
+
* **Summary:** Highly motivated and results-oriented software engineer with 5+ years of experience in developing and maintaining complex software applications. Proven ability to work independently and as part of a team.
|
274 |
+
* **Technical Skills:** Proficient in Java, Python, C++, and SQL. Experience with Agile methodologies and cloud computing platforms.
|
275 |
+
* **Experience:**
|
276 |
+
* Developed a new customer relationship management system that resulted in a 20% increase in sales.
|
277 |
+
* Led a team of engineers in the development of a new mobile app that has been downloaded over 1 million times.
|
278 |
+
* **Education:** Bachelor of Science in Computer Science from the University of California, Berkeley.
|
279 |
+
|
280 |
+
**Steps:**
|
281 |
+
|
282 |
+
1. Review the candidate's resume and identify their key skills and experience.
|
283 |
+
2. Determine the target job description and identify the most relevant information from the resume.
|
284 |
+
3. Write a concise and impactful summary of the candidate's qualifications.
|
285 |
+
4. Highlight the candidate's technical skills and experience.
|
286 |
+
5. Provide specific examples of the candidate's accomplishments.
|
287 |
+
6. Proofread the resume brief carefully.
|
288 |
+
|
289 |
+
**Goal:**
|
290 |
+
|
291 |
+
To generate a well-structured, impactful resume brief that effectively showcases the candidate's qualifications and increases their chances of landing an interview.
|
292 |
+
|
293 |
+
**Additional Notes:**
|
294 |
+
|
295 |
+
* Consider including a call to action at the end of the resume brief, such as "Please contact me to discuss my qualifications in more detail."
|
296 |
+
* You may also want to include a link to the candidate's full resume.
|
297 |
+
* If you have any questions about the candidate's qualifications, be sure to reach out to them for clarification.
|
298 |
+
|
299 |
+
**By following these guidelines and steps, you can generate an effective prompt that will help the model generate a well-structured, impactful resume brief in one go.**
|
300 |
+
|
301 |
+
Details: {details}
|
302 |
+
"""
|
303 |
return prompt
|
304 |
|
305 |
+
|
306 |
+
|
307 |
def validation_prompt(code, guidelines=None):
|
308 |
prompt=f"""Check if the below input contains code snippets or not. Return only Yes or NO and nothing else.
|
309 |
Input: {code}
|