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