Anmol3263 commited on
Commit
9fe803d
·
verified ·
1 Parent(s): 87d2394

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -21
app.py CHANGED
@@ -2,42 +2,33 @@ import gradio as gr
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
 
37
- iface = gr.ChatInterface(
38
  fn=chat,
39
  title="Jarvis AI 🤖",
40
  description="Internal AI Assistant"
41
  )
42
 
43
- iface.launch(server_name="0.0.0.0", server_port=7860)
 
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)