Download Backend.py from Canstralian/Python_Code_Assistance: direct link, hf CLI and curl.
- Browser
- Download file 839 Bytes
-
https://huggingface.co/spaces/Canstralian/Python_Code_Assistance/resolve/5658a53afa046d7075c4cb8ff8925fd33c613d5e/Backend.py
- Command line
-
hf download hf://spaces/Canstralian/Python_Code_Assistance@5658a53afa046d7075c4cb8ff8925fd33c613d5e/Backend.py
-
curl -L -o Backend.py https://huggingface.co/spaces/Canstralian/Python_Code_Assistance/resolve/5658a53afa046d7075c4cb8ff8925fd33c613d5e/Backend.py
839 Bytes
| 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): | |
| 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(question): | |
| prompt = ["You are Python coding assistant generate only question and answer based of the given code" | |
| , question] | |
| response = generativeai.GenerativeModel('gemini-pro').generate_content(prompt) | |
| return response.text if response else "No answer available." | |