Update app.py
Browse files
app.py
CHANGED
|
@@ -2,33 +2,35 @@ import gradio as gr
|
|
| 2 |
import google.generativeai as genai
|
| 3 |
import os
|
| 4 |
|
| 5 |
-
|
|
|
|
| 6 |
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
def chat(message, history):
|
| 10 |
try:
|
|
|
|
|
|
|
| 11 |
response = model.generate_content(message)
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
else:
|
| 17 |
-
reply = "⚠️ No response from AI"
|
| 18 |
|
| 19 |
history.append((message, reply))
|
| 20 |
return history, history
|
| 21 |
|
| 22 |
except Exception as e:
|
| 23 |
-
print("ERROR:", e)
|
| 24 |
-
history.append((message, f"
|
| 25 |
return history, history
|
| 26 |
|
| 27 |
|
| 28 |
-
demo = gr.ChatInterface(
|
| 29 |
-
fn=chat,
|
| 30 |
-
title="Jarvis AI 🤖",
|
| 31 |
-
description="Internal AI Assistant"
|
| 32 |
-
)
|
| 33 |
|
| 34 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
| 2 |
import google.generativeai as genai
|
| 3 |
import os
|
| 4 |
|
| 5 |
+
api_key = os.getenv("GEMINI_API_KEY")
|
| 6 |
+
print("API KEY:", api_key) # DEBUG
|
| 7 |
|
| 8 |
+
if not api_key:
|
| 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 |
+
print("Full response:", response)
|
| 22 |
+
|
| 23 |
+
reply = response.text
|
|
|
|
|
|
|
| 24 |
|
| 25 |
history.append((message, reply))
|
| 26 |
return history, history
|
| 27 |
|
| 28 |
except Exception as e:
|
| 29 |
+
print("🔥 ERROR:", str(e)) # <-- ye important hai
|
| 30 |
+
history.append((message, f"ERROR: {str(e)}"))
|
| 31 |
return history, history
|
| 32 |
|
| 33 |
|
| 34 |
+
demo = gr.ChatInterface(fn=chat)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|