Update app.py
Browse files
app.py
CHANGED
|
@@ -2,31 +2,35 @@ import gradio as gr
|
|
| 2 |
import google.generativeai as genai
|
| 3 |
import os
|
| 4 |
|
| 5 |
-
#
|
|
|
|
|
|
|
| 6 |
api_key = os.getenv("GEMINI_API_KEY")
|
| 7 |
|
| 8 |
if not api_key:
|
| 9 |
-
raise ValueError("API
|
| 10 |
|
| 11 |
genai.configure(api_key=api_key)
|
| 12 |
|
| 13 |
model = genai.GenerativeModel("gemini-1.5-flash")
|
| 14 |
|
| 15 |
-
chat_session = model.start_chat(history=[])
|
| 16 |
-
|
| 17 |
def chat(user_input, history):
|
| 18 |
try:
|
| 19 |
-
|
| 20 |
-
|
|
|
|
| 21 |
|
| 22 |
-
response
|
| 23 |
-
|
|
|
|
|
|
|
| 24 |
|
| 25 |
history.append((user_input, reply))
|
| 26 |
return history, history
|
| 27 |
|
| 28 |
except Exception as e:
|
| 29 |
-
|
|
|
|
| 30 |
return history, history
|
| 31 |
|
| 32 |
|
|
|
|
| 2 |
import google.generativeai as genai
|
| 3 |
import os
|
| 4 |
|
| 5 |
+
# Debug print (logs me dikhega)
|
| 6 |
+
print("Starting Jarvis...")
|
| 7 |
+
|
| 8 |
api_key = os.getenv("GEMINI_API_KEY")
|
| 9 |
|
| 10 |
if not api_key:
|
| 11 |
+
raise ValueError("❌ API KEY NOT FOUND")
|
| 12 |
|
| 13 |
genai.configure(api_key=api_key)
|
| 14 |
|
| 15 |
model = genai.GenerativeModel("gemini-1.5-flash")
|
| 16 |
|
|
|
|
|
|
|
| 17 |
def chat(user_input, history):
|
| 18 |
try:
|
| 19 |
+
print("User input:", user_input)
|
| 20 |
+
|
| 21 |
+
response = model.generate_content(user_input)
|
| 22 |
|
| 23 |
+
if not response or not response.text:
|
| 24 |
+
reply = "⚠️ No response from AI"
|
| 25 |
+
else:
|
| 26 |
+
reply = response.text
|
| 27 |
|
| 28 |
history.append((user_input, reply))
|
| 29 |
return history, history
|
| 30 |
|
| 31 |
except Exception as e:
|
| 32 |
+
print("ERROR:", str(e)) # logs me exact error dikhega
|
| 33 |
+
history.append((user_input, f"❌ Error: {str(e)}"))
|
| 34 |
return history, history
|
| 35 |
|
| 36 |
|