Update app.py
Browse files
app.py
CHANGED
|
@@ -1,32 +1,26 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
| 3 |
import os
|
| 4 |
|
| 5 |
-
#
|
| 6 |
API_KEY = os.getenv("GOOGLE_API_KEY")
|
| 7 |
|
| 8 |
if not API_KEY:
|
| 9 |
-
raise Exception("❌ API key
|
| 10 |
|
| 11 |
-
#
|
| 12 |
-
genai.
|
| 13 |
-
|
| 14 |
-
# Use stable model
|
| 15 |
-
model = genai.GenerativeModel("gemini-1.0-pro")
|
| 16 |
|
| 17 |
def chat(message, history):
|
| 18 |
try:
|
| 19 |
-
response =
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 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()
|
|
|