Update app.py
Browse files
app.py
CHANGED
|
@@ -2,34 +2,32 @@ import gradio as gr
|
|
| 2 |
import google.generativeai as genai
|
| 3 |
import os
|
| 4 |
|
| 5 |
-
# API KEY
|
| 6 |
API_KEY = os.getenv("GEMINI_API_KEY")
|
| 7 |
|
| 8 |
if not API_KEY:
|
| 9 |
-
raise Exception("
|
| 10 |
|
| 11 |
genai.configure(api_key=API_KEY)
|
| 12 |
|
| 13 |
-
# simple working model
|
| 14 |
model = genai.GenerativeModel("gemini-1.5-flash")
|
| 15 |
|
| 16 |
def chat(message, history):
|
| 17 |
try:
|
| 18 |
response = model.generate_content(message)
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
if hasattr(response, "text") and response.text:
|
| 23 |
-
reply = response.text
|
| 24 |
else:
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
return reply
|
| 28 |
|
| 29 |
except Exception as e:
|
| 30 |
-
return f"
|
| 31 |
|
| 32 |
|
| 33 |
-
demo = gr.ChatInterface(
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
demo.launch()
|
|
|
|
| 2 |
import google.generativeai as genai
|
| 3 |
import os
|
| 4 |
|
| 5 |
+
# API KEY
|
| 6 |
API_KEY = os.getenv("GEMINI_API_KEY")
|
| 7 |
|
| 8 |
if not API_KEY:
|
| 9 |
+
raise Exception("API KEY missing")
|
| 10 |
|
| 11 |
genai.configure(api_key=API_KEY)
|
| 12 |
|
|
|
|
| 13 |
model = genai.GenerativeModel("gemini-1.5-flash")
|
| 14 |
|
| 15 |
def chat(message, history):
|
| 16 |
try:
|
| 17 |
response = model.generate_content(message)
|
| 18 |
|
| 19 |
+
if response and hasattr(response, "text"):
|
| 20 |
+
return response.text
|
|
|
|
|
|
|
| 21 |
else:
|
| 22 |
+
return "No response"
|
|
|
|
|
|
|
| 23 |
|
| 24 |
except Exception as e:
|
| 25 |
+
return f"Error: {str(e)}"
|
| 26 |
|
| 27 |
|
| 28 |
+
demo = gr.ChatInterface(
|
| 29 |
+
fn=chat,
|
| 30 |
+
type="messages" # 👈 IMPORTANT FIX
|
| 31 |
+
)
|
| 32 |
|
| 33 |
demo.launch()
|