Spaces:
Sleeping
Sleeping
updated multiple question options
Browse files- Backend.py +35 -3
Backend.py
CHANGED
|
@@ -7,6 +7,9 @@ load_dotenv()
|
|
| 7 |
generativeai.configure(api_key=os.getenv("GOOGLE_GEMINI_KEY"))
|
| 8 |
|
| 9 |
def get_correction_and_comments(code_snippet):
|
|
|
|
|
|
|
|
|
|
| 10 |
prompt = [
|
| 11 |
"Analyze and correct the following Python code, add comments, and format it:",
|
| 12 |
code_snippet
|
|
@@ -14,8 +17,37 @@ def get_correction_and_comments(code_snippet):
|
|
| 14 |
response = generativeai.GenerativeModel('gemini-pro').generate_content(prompt)
|
| 15 |
return response.text if response else "No suggestions available."
|
| 16 |
|
| 17 |
-
def generate_questions(
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
response = generativeai.GenerativeModel('gemini-pro').generate_content(prompt)
|
| 21 |
return response.text if response else "No answer available."
|
|
|
|
| 7 |
generativeai.configure(api_key=os.getenv("GOOGLE_GEMINI_KEY"))
|
| 8 |
|
| 9 |
def get_correction_and_comments(code_snippet):
|
| 10 |
+
"""
|
| 11 |
+
Analyze, correct, and comment on the given Python code.
|
| 12 |
+
"""
|
| 13 |
prompt = [
|
| 14 |
"Analyze and correct the following Python code, add comments, and format it:",
|
| 15 |
code_snippet
|
|
|
|
| 17 |
response = generativeai.GenerativeModel('gemini-pro').generate_content(prompt)
|
| 18 |
return response.text if response else "No suggestions available."
|
| 19 |
|
| 20 |
+
def generate_questions(code_snippet, question_type):
|
| 21 |
+
"""
|
| 22 |
+
Generate questions and answers based on the user's choice of question type.
|
| 23 |
+
|
| 24 |
+
Parameters:
|
| 25 |
+
- code_snippet: The Python code to generate questions for.
|
| 26 |
+
- question_type: The type of questions to generate.
|
| 27 |
+
|
| 28 |
+
Returns:
|
| 29 |
+
- Generated questions and answers as text.
|
| 30 |
+
"""
|
| 31 |
+
if question_type == "Logical Questions":
|
| 32 |
+
prompt = [
|
| 33 |
+
"Analyze the following Python code and generate logical reasoning questions and answers:",
|
| 34 |
+
code_snippet
|
| 35 |
+
]
|
| 36 |
+
elif question_type == "Interview-Based Questions":
|
| 37 |
+
prompt = [
|
| 38 |
+
"Analyze the following Python code and generate interview-style questions and answers for developers:",
|
| 39 |
+
code_snippet
|
| 40 |
+
]
|
| 41 |
+
elif question_type == "Code Analysis Questions":
|
| 42 |
+
prompt = [
|
| 43 |
+
"Analyze the following Python code and generate in-depth code analysis questions with answers:",
|
| 44 |
+
code_snippet
|
| 45 |
+
]
|
| 46 |
+
else:
|
| 47 |
+
prompt = [
|
| 48 |
+
"Generate general Python questions and answers based on the given code:",
|
| 49 |
+
code_snippet
|
| 50 |
+
]
|
| 51 |
+
|
| 52 |
response = generativeai.GenerativeModel('gemini-pro').generate_content(prompt)
|
| 53 |
return response.text if response else "No answer available."
|