HaiderAUT commited on
Commit
660b355
·
verified ·
1 Parent(s): ada8bb3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -7
app.py CHANGED
@@ -5,6 +5,29 @@ import yaml
5
  from tools.final_answer import FinalAnswerTool
6
  from Gradio_UI import GradioUI
7
  from google import genai
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
  # Import AgentText to return a composite Markdown message
10
  from smolagents.agent_types import AgentText
@@ -58,17 +81,11 @@ def my_custom_tool(arg1: str, arg2: int) -> str:
58
  messages.append(f"Note: {arg1}")
59
 
60
  return "\n".join(messages)
61
- @tool
62
 
63
 
64
 
65
 
66
- response = client.models.generate_content(
67
- model="gemini-2.0-flash",
68
- config=types.GenerateContentConfig(
69
- system_instruction="You are a cat. Your name is Neko."),
70
- contents="Hello there"
71
- )
72
 
73
  print(response.text)
74
 
 
5
  from tools.final_answer import FinalAnswerTool
6
  from Gradio_UI import GradioUI
7
  from google import genai
8
+ from dotenv import load_dotenv
9
+ load_dotenv()
10
+ gemini_api_key = os.getenv("GEMINI_API_KEY")
11
+ if not gemini_api_key:
12
+ # Option 1: Raise an error if the key is absolutely required
13
+ raise ValueError("GEMINI_API_KEY environment variable not set. Please set it in Spaces Secrets.")
14
+ # Option 2: Handle gracefully (e.g., disable features, show a message)
15
+ # print("Warning: GEMINI_API_KEY not found. Gemini features will be disabled.")
16
+ # gemini_features_enabled = False
17
+ else:
18
+ # print("Gemini API Key found.") # Avoid printing the key itself!
19
+ # gemini_features_enabled = True
20
+ # --- Configure the Gemini client ---
21
+ try:
22
+ genai.configure(api_key=gemini_api_key)
23
+ print("Gemini client configured successfully.")
24
+ # You can now initialize your model, e.g.:
25
+ # model = genai.GenerativeModel('gemini-pro')
26
+ # response = model.generate_content("Tell me a joke.")
27
+ # print(response.text)
28
+ except Exception as e:
29
+ print(f"Error configuring Gemini client: {e}")
30
+
31
 
32
  # Import AgentText to return a composite Markdown message
33
  from smolagents.agent_types import AgentText
 
81
  messages.append(f"Note: {arg1}")
82
 
83
  return "\n".join(messages)
84
+
85
 
86
 
87
 
88
 
 
 
 
 
 
 
89
 
90
  print(response.text)
91