dcata004 commited on
Commit
2dfb9db
·
verified ·
1 Parent(s): 06922f2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -12
app.py CHANGED
@@ -1,18 +1,19 @@
1
  import os
2
- import sys
3
-
4
- # --- HUGGING FACE CHROMADB FIX ---
5
- # Forces the use of pysqlite3-binary to avoid DB crashes
6
- try:
7
- __import__('pysqlite3')
8
- sys.modules['sqlite3'] = sys.modules.pop('pysqlite3')
9
- except ImportError:
10
- # If this fails, we continue, but it might crash later if the system sqlite is old
11
- pass
12
- # ---------------------------------
13
-
14
  import gradio as gr
 
15
  from langchain_openai import ChatOpenAI, OpenAIEmbeddings
 
 
 
 
 
 
 
 
 
 
 
 
16
  from langchain_community.document_loaders import PyPDFLoader
17
  from langchain_text_splitters import RecursiveCharacterTextSplitter
18
  from langchain_chroma import Chroma
 
1
  import os
 
 
 
 
 
 
 
 
 
 
 
 
2
  import gradio as gr
3
+ from langchain_community.document_loaders import PyPDFLoader
4
  from langchain_openai import ChatOpenAI, OpenAIEmbeddings
5
+
6
+ # --- DEBUG & SETUP ---
7
+ api_key = os.getenv("OPENAI_API_KEY")
8
+
9
+ # Check if Key is missing and warn the logs
10
+ if not api_key:
11
+ print("⚠️ CRITICAL ERROR: OPENAI_API_KEY is missing from Secrets.")
12
+ # Fallback: Try to grab it if user named it differently
13
+ api_key = os.getenv("OPENAI_KEY") or os.getenv("key")
14
+
15
+ # Force set the variable for LangChain
16
+ os.environ["OPENAI_API_KEY"] = str(api_key)
17
  from langchain_community.document_loaders import PyPDFLoader
18
  from langchain_text_splitters import RecursiveCharacterTextSplitter
19
  from langchain_chroma import Chroma