| import os | |
| import google.generativeai as genai | |
| # Fetch the API key from the environment variable (Space secret) | |
| api_key = os.getenv("GOOGLE_API_KEY") | |
| if not api_key: | |
| raise ValueError("GOOGLE_API_KEY secret not set in Hugging Face Space settings.") | |
| # Configure the Gemini API | |
| genai.configure(api_key=api_key) | |
| # Initialize the model | |
| # You can change 'gemini-1.5-flash-latest' to 'gemini-1.5-pro-latest' or other models | |
| model = genai.GenerativeModel('gemini-1.5-flash-latest') | |
| # Get user input from the terminal | |
| prompt = input("Enter your prompt for Gemini: ") | |
| print("\nGenerating response...") | |
| # Generate content | |
| response = model.generate_content(prompt) | |
| # Print the response text | |
| print("\n--- Gemini Response ---") | |
| print(response.text) | |
| print("-----------------------\n") |