Update app.py
Browse files
app.py
CHANGED
|
@@ -2,41 +2,35 @@ import gradio as gr
|
|
| 2 |
import google.generativeai as genai
|
| 3 |
import os
|
| 4 |
|
| 5 |
-
# Configure API
|
| 6 |
genai.configure(api_key=os.getenv("GEMINI_API_KEY"))
|
| 7 |
|
| 8 |
-
#
|
| 9 |
-
model = genai.GenerativeModel("gemini-
|
| 10 |
|
| 11 |
def chat(message, history):
|
| 12 |
try:
|
| 13 |
-
print("Incoming message:", message)
|
| 14 |
-
|
| 15 |
response = model.generate_content(message)
|
| 16 |
-
print("Raw response:", response)
|
| 17 |
|
| 18 |
reply = ""
|
| 19 |
-
|
| 20 |
try:
|
| 21 |
reply = response.text
|
| 22 |
-
except
|
| 23 |
-
print("TEXT ERROR:", e)
|
| 24 |
reply = str(response)
|
| 25 |
|
| 26 |
history.append((message, reply))
|
| 27 |
return history, history
|
| 28 |
|
| 29 |
except Exception as e:
|
| 30 |
-
print("
|
| 31 |
history.append((message, f"Error: {str(e)}"))
|
| 32 |
return history, history
|
| 33 |
|
| 34 |
-
#
|
| 35 |
demo = gr.ChatInterface(
|
| 36 |
fn=chat,
|
| 37 |
title="Jarvis AI 🤖",
|
| 38 |
description="Internal AI Assistant"
|
| 39 |
)
|
| 40 |
|
| 41 |
-
|
| 42 |
-
demo.launch(server_name="0.0.0.0", server_port=7860, ssr_mode=False)
|
|
|
|
| 2 |
import google.generativeai as genai
|
| 3 |
import os
|
| 4 |
|
| 5 |
+
# 🔑 Configure API
|
| 6 |
genai.configure(api_key=os.getenv("GEMINI_API_KEY"))
|
| 7 |
|
| 8 |
+
# 🤖 Model
|
| 9 |
+
model = genai.GenerativeModel("gemini-1.5-flash")
|
| 10 |
|
| 11 |
def chat(message, history):
|
| 12 |
try:
|
|
|
|
|
|
|
| 13 |
response = model.generate_content(message)
|
|
|
|
| 14 |
|
| 15 |
reply = ""
|
|
|
|
| 16 |
try:
|
| 17 |
reply = response.text
|
| 18 |
+
except:
|
|
|
|
| 19 |
reply = str(response)
|
| 20 |
|
| 21 |
history.append((message, reply))
|
| 22 |
return history, history
|
| 23 |
|
| 24 |
except Exception as e:
|
| 25 |
+
print("ERROR:", e)
|
| 26 |
history.append((message, f"Error: {str(e)}"))
|
| 27 |
return history, history
|
| 28 |
|
| 29 |
+
# UI
|
| 30 |
demo = gr.ChatInterface(
|
| 31 |
fn=chat,
|
| 32 |
title="Jarvis AI 🤖",
|
| 33 |
description="Internal AI Assistant"
|
| 34 |
)
|
| 35 |
|
| 36 |
+
demo.launch()
|
|
|