BOB0920 commited on
Commit
1dee3ac
Β·
verified Β·
1 Parent(s): 18daf7f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -10
app.py CHANGED
@@ -11,14 +11,22 @@ sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), "src"))
11
  from dotenv import load_dotenv
12
  load_dotenv()
13
 
14
- # Check API key BEFORE importing rag (which needs it)
15
  api_key = os.getenv("GOOGLE_API_KEY")
16
  if not api_key:
17
  st.error("⚠️ **GOOGLE_API_KEY is missing!**")
18
- st.info("Please add your Google API key to the Secrets in your Hugging Face Space settings, or create a `.env` file with `GOOGLE_API_KEY=your_key_here`")
19
  st.stop()
20
 
21
- from src.rag import get_answer
 
 
 
 
 
 
 
 
22
 
23
  # Title
24
  st.title("🌟 Sagar's Personal Assistant")
@@ -47,14 +55,10 @@ if prompt := st.chat_input("What would you like to know?"):
47
  response = get_answer(prompt)
48
  if response:
49
  st.markdown(response)
50
- # Add assistant message to history
51
  st.session_state.messages.append({"role": "assistant", "content": response})
52
  else:
53
- st.error("❌ Received empty response from the AI. Please try again.")
54
  except Exception as e:
55
- error_msg = f"❌ An error occurred: {str(e)}"
56
- st.error(error_msg)
57
- # Also log to console for debugging
58
- print(f"Error in get_answer: {e}")
59
  import traceback
60
- traceback.print_exc()
 
11
  from dotenv import load_dotenv
12
  load_dotenv()
13
 
14
+ # Debug: Show if API key is loaded
15
  api_key = os.getenv("GOOGLE_API_KEY")
16
  if not api_key:
17
  st.error("⚠️ **GOOGLE_API_KEY is missing!**")
18
+ st.info("πŸ‘‰ Go to your HF Space **Settings β†’ Secrets** and add `GOOGLE_API_KEY` with your Google AI Studio API key.")
19
  st.stop()
20
 
21
+ # Try importing rag and show any import errors
22
+ try:
23
+ from src.rag import get_answer
24
+ st.success("βœ… RAG module loaded successfully!")
25
+ except Exception as e:
26
+ st.error(f"❌ Failed to import RAG module: {e}")
27
+ import traceback
28
+ st.code(traceback.format_exc())
29
+ st.stop()
30
 
31
  # Title
32
  st.title("🌟 Sagar's Personal Assistant")
 
55
  response = get_answer(prompt)
56
  if response:
57
  st.markdown(response)
 
58
  st.session_state.messages.append({"role": "assistant", "content": response})
59
  else:
60
+ st.error("❌ Received empty response from AI.")
61
  except Exception as e:
62
+ st.error(f"❌ Error: {str(e)}")
 
 
 
63
  import traceback
64
+ st.code(traceback.format_exc())