Update app.py
Browse files
app.py
CHANGED
|
@@ -2,24 +2,26 @@ import gradio as gr
|
|
| 2 |
import google.generativeai as genai
|
| 3 |
import os
|
| 4 |
|
| 5 |
-
# π DEBUG
|
| 6 |
-
|
|
|
|
| 7 |
|
| 8 |
-
#
|
| 9 |
-
|
|
|
|
| 10 |
|
| 11 |
-
#
|
|
|
|
|
|
|
|
|
|
| 12 |
model = genai.GenerativeModel("gemini-1.5-flash")
|
| 13 |
|
| 14 |
def chat(message, history):
|
| 15 |
try:
|
| 16 |
response = model.generate_content(message)
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
reply = response.text
|
| 21 |
-
except:
|
| 22 |
-
reply = str(response)
|
| 23 |
|
| 24 |
history.append((message, reply))
|
| 25 |
return history, history
|
|
|
|
| 2 |
import google.generativeai as genai
|
| 3 |
import os
|
| 4 |
|
| 5 |
+
# π DEBUG - check API key
|
| 6 |
+
api_key = os.getenv("GEMINI_API_KEY")
|
| 7 |
+
print("API KEY:", api_key)
|
| 8 |
|
| 9 |
+
# β agar key nahi hai to error de
|
| 10 |
+
if not api_key:
|
| 11 |
+
raise ValueError("GEMINI_API_KEY not found in environment!")
|
| 12 |
|
| 13 |
+
# π configure Gemini
|
| 14 |
+
genai.configure(api_key=api_key)
|
| 15 |
+
|
| 16 |
+
# π€ use stable model
|
| 17 |
model = genai.GenerativeModel("gemini-1.5-flash")
|
| 18 |
|
| 19 |
def chat(message, history):
|
| 20 |
try:
|
| 21 |
response = model.generate_content(message)
|
| 22 |
|
| 23 |
+
# safe extraction
|
| 24 |
+
reply = getattr(response, "text", str(response))
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
history.append((message, reply))
|
| 27 |
return history, history
|