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