Update app.py
Browse files
app.py
CHANGED
|
@@ -2,42 +2,33 @@ import gradio as gr
|
|
| 2 |
import google.generativeai as genai
|
| 3 |
import os
|
| 4 |
|
| 5 |
-
|
| 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(
|
| 18 |
try:
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
response = model.generate_content(user_input)
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
else:
|
| 26 |
reply = response.text
|
|
|
|
|
|
|
| 27 |
|
| 28 |
-
history.append((
|
| 29 |
return history, history
|
| 30 |
|
| 31 |
except Exception as e:
|
| 32 |
-
print("ERROR:",
|
| 33 |
-
history.append((
|
| 34 |
return history, history
|
| 35 |
|
| 36 |
|
| 37 |
-
|
| 38 |
fn=chat,
|
| 39 |
title="Jarvis AI 🤖",
|
| 40 |
description="Internal AI Assistant"
|
| 41 |
)
|
| 42 |
|
| 43 |
-
|
|
|
|
| 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 |
+
reply = ""
|
| 14 |
+
if response and hasattr(response, "text"):
|
|
|
|
| 15 |
reply = response.text
|
| 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"❌ {str(e)}"))
|
| 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)
|