Spaces:
Sleeping
Sleeping
File size: 644 Bytes
5f277bb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | import os
from google import genai
from dotenv import load_dotenv
# Load the API key from your .env file
load_dotenv()
print("Attempting to connect to Gemini API...")
try:
client = genai.Client(api_key=os.getenv("GEMINI_API_KEY"))
# A simple, tiny request
response = client.models.generate_content(
model='gemini-2.5-flash',
contents='Reply with the exact words: "Connection Successful!"'
)
print("\n✅ SUCCESS! The API is reachable.")
print(f"Gemini says: {response.text}")
except Exception as e:
print("\n❌ FAILED. The network block is still active.")
print(f"Error Details: {str(e)}") |