Download test_gemini.py from andrewnzrv/Final_Assignment_Template: direct link, hf CLI and curl.
- Browser
- Download file 908 Bytes
-
https://huggingface.co/spaces/andrewnzrv/Final_Assignment_Template/resolve/main/test_gemini.py
- Command line
-
hf download hf://spaces/andrewnzrv/Final_Assignment_Template/test_gemini.py
-
curl -L -o test_gemini.py https://huggingface.co/spaces/andrewnzrv/Final_Assignment_Template/resolve/main/test_gemini.py
908 Bytes
| import os | |
| import google.generativeai as genai | |
| import sys | |
| # Print Python environment info | |
| print(f"Python version: {sys.version}") | |
| print(f"Python executable: {sys.executable}") | |
| # Configure the library with your API key | |
| api_key = os.getenv('GEMINI_API_KEY') | |
| print(f"API Key found: {'Yes' if api_key else 'No'}") | |
| print(f"API Key value: {api_key[:4]}...{api_key[-4:] if api_key else 'None'}") # Show first and last 4 chars safely | |
| try: | |
| # Configure genai | |
| genai.configure(api_key=api_key) | |
| # List available models | |
| print("\nAvailable models:") | |
| for m in genai.list_models(): | |
| print(m.name) | |
| # Initialize the model | |
| model = genai.GenerativeModel('models/gemini-2.0-flash-lite') | |
| # Generate a response | |
| response = model.generate_content("Say hello!") | |
| print("\nTest response:", response.text) | |
| except Exception as e: | |
| print("\nError occurred:", str(e)) |