Anmol3263 commited on
Commit
aff9622
·
verified ·
1 Parent(s): 23843b0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -4
app.py CHANGED
@@ -1,12 +1,18 @@
 
 
 
 
 
 
 
 
1
  def chat(message, history):
2
  try:
3
  response = model.generate_content(message)
4
 
5
- # Safe extraction
6
  if hasattr(response, "text") and response.text:
7
  reply = response.text
8
- elif hasattr(response, "candidates"):
9
- reply = response.candidates[0].content.parts[0].text
10
  else:
11
  reply = "No response from AI"
12
 
@@ -16,4 +22,13 @@ def chat(message, history):
16
  except Exception as e:
17
  print("ERROR:", e)
18
  history.append((message, f"Error: {str(e)}"))
19
- return history, history
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ import google.generativeai as genai
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 hasattr(response, "text") and response.text:
15
  reply = response.text
 
 
16
  else:
17
  reply = "No response from AI"
18
 
 
22
  except Exception as e:
23
  print("ERROR:", e)
24
  history.append((message, f"Error: {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()