Anmol3263 commited on
Commit
262e19a
Β·
verified Β·
1 Parent(s): 70fbcd4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -22
app.py CHANGED
@@ -2,41 +2,34 @@ import gradio as gr
2
  import google.generativeai as genai
3
  import os
4
 
5
- # πŸ” DEBUG - check API key
6
- api_key = os.getenv("GEMINI_API_KEY")
7
- print("API KEY:", api_key)
8
 
9
- # ❌ agar key nahi hai to error de
10
- if not api_key:
11
- raise ValueError("GEMINI_API_KEY not found in environment!")
12
 
13
- # πŸ”‘ configure Gemini
14
- genai.configure(api_key=api_key)
15
 
16
- # πŸ€– use stable model
17
  model = genai.GenerativeModel("gemini-1.5-flash")
18
 
19
  def chat(message, history):
20
  try:
21
  response = model.generate_content(message)
22
 
23
- # safe extraction
24
- reply = getattr(response, "text", str(response))
 
 
 
 
25
 
26
- history.append((message, reply))
27
- return history, history
28
 
29
  except Exception as e:
30
- error_msg = f"πŸ”₯ ERROR: {str(e)}"
31
- print(error_msg)
32
- history.append((message, error_msg))
33
- return history, history
34
 
35
 
36
- demo = gr.ChatInterface(
37
- fn=chat,
38
- title="Jarvis AI πŸ€–",
39
- description="Internal AI Assistant"
40
- )
41
 
42
  demo.launch()
 
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 Exception("❌ GEMINI_API_KEY missing in Secrets")
 
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
+ # safest extraction
21
+ reply = ""
22
+ if hasattr(response, "text") and response.text:
23
+ reply = response.text
24
+ else:
25
+ reply = "⚠️ No response from model"
26
 
27
+ return reply
 
28
 
29
  except Exception as e:
30
+ return f"πŸ”₯ ERROR: {str(e)}"
 
 
 
31
 
32
 
33
+ demo = gr.ChatInterface(fn=chat)
 
 
 
 
34
 
35
  demo.launch()