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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -9
app.py CHANGED
@@ -2,31 +2,35 @@ import gradio as gr
2
  import google.generativeai as genai
3
  import os
4
 
5
- # API key check
 
 
6
  api_key = os.getenv("GEMINI_API_KEY")
7
 
8
  if not api_key:
9
- raise ValueError("API key not found! Check Hugging Face Variables.")
10
 
11
  genai.configure(api_key=api_key)
12
 
13
  model = genai.GenerativeModel("gemini-1.5-flash")
14
 
15
- chat_session = model.start_chat(history=[])
16
-
17
  def chat(user_input, history):
18
  try:
19
- if not user_input:
20
- return history, history
 
21
 
22
- response = chat_session.send_message(user_input)
23
- reply = response.text if response.text else "No response from AI"
 
 
24
 
25
  history.append((user_input, reply))
26
  return history, history
27
 
28
  except Exception as e:
29
- history.append((user_input, f"Error: {str(e)}"))
 
30
  return history, history
31
 
32
 
 
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