HuggingFaceDAO commited on
Commit
8c7ad0f
·
verified ·
1 Parent(s): e504961

Create gemini_tool.py

Browse files
Files changed (1) hide show
  1. gemini_tool.py +28 -0
gemini_tool.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import google.generativeai as genai
3
+
4
+ # Fetch the API key from the environment variable (Space secret)
5
+ api_key = os.getenv("GOOGLE_API_KEY")
6
+
7
+ if not api_key:
8
+ raise ValueError("GOOGLE_API_KEY secret not set in Hugging Face Space settings.")
9
+
10
+ # Configure the Gemini API
11
+ genai.configure(api_key=api_key)
12
+
13
+ # Initialize the model
14
+ # You can change 'gemini-1.5-flash-latest' to 'gemini-1.5-pro-latest' or other models
15
+ model = genai.GenerativeModel('gemini-1.5-flash-latest')
16
+
17
+ # Get user input from the terminal
18
+ prompt = input("Enter your prompt for Gemini: ")
19
+
20
+ print("\nGenerating response...")
21
+
22
+ # Generate content
23
+ response = model.generate_content(prompt)
24
+
25
+ # Print the response text
26
+ print("\n--- Gemini Response ---")
27
+ print(response.text)
28
+ print("-----------------------\n")