Anmol3263 commited on
Commit
8727d86
·
verified ·
1 Parent(s): 8a8e5de

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -17
app.py CHANGED
@@ -1,32 +1,26 @@
1
  import gradio as gr
2
- import google.generativeai as genai
3
  import os
4
 
5
- # Load API key
6
  API_KEY = os.getenv("GOOGLE_API_KEY")
7
 
8
  if not API_KEY:
9
- raise Exception("❌ API key not found in secrets")
10
 
11
- # Configure Gemini
12
- genai.configure(api_key=API_KEY)
13
-
14
- # Use stable model
15
- model = genai.GenerativeModel("gemini-1.0-pro")
16
 
17
  def chat(message, history):
18
  try:
19
- response = model.generate_content(message)
20
-
21
- if response and hasattr(response, "text"):
22
- return response.text
23
- else:
24
- return "⚠️ No response from AI"
25
 
26
  except Exception as e:
27
  return f"❌ Error: {str(e)}"
28
 
29
- # UI
30
  iface = gr.ChatInterface(fn=chat, title="Jarvis AI 🤖")
31
-
32
- iface.launch()
 
1
  import gradio as gr
2
+ from google import genai
3
  import os
4
 
5
+ # API KEY
6
  API_KEY = os.getenv("GOOGLE_API_KEY")
7
 
8
  if not API_KEY:
9
+ raise Exception("❌ API key missing")
10
 
11
+ # New client (IMPORTANT)
12
+ client = genai.Client(api_key=API_KEY)
 
 
 
13
 
14
  def chat(message, history):
15
  try:
16
+ response = client.models.generate_content(
17
+ model="gemini-1.5-flash",
18
+ contents=message
19
+ )
20
+ return response.text
 
21
 
22
  except Exception as e:
23
  return f"❌ Error: {str(e)}"
24
 
 
25
  iface = gr.ChatInterface(fn=chat, title="Jarvis AI 🤖")
26
+ iface.launch()