Jaal047 commited on
Commit
4949586
·
verified ·
1 Parent(s): ef5508d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -5
app.py CHANGED
@@ -1,18 +1,25 @@
1
  import os
2
  import gradio as gr
3
  from langchain_community.vectorstores import FAISS
4
- from langchain_community.embeddings import HuggingFaceEmbeddings
5
  from groq import Groq
6
 
7
- # Load FAISS index dengan deserialization yang aman
 
 
 
 
 
 
 
8
  vector_store = FAISS.load_local(
9
- "faiss_index/robohome_faiss",
10
  HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-L6-v2"),
11
- allow_dangerous_deserialization=True
12
  )
13
 
14
  # Load API Key dari variabel lingkungan
15
- GROQ_API_KEY = os.getenv("GROQ_API_KEY")
16
  if not GROQ_API_KEY:
17
  raise ValueError("⚠️ API Key Groq tidak ditemukan! Setel variabel lingkungan 'GROQ_API_KEY'.")
18
 
 
1
  import os
2
  import gradio as gr
3
  from langchain_community.vectorstores import FAISS
4
+ from langchain_huggingface import HuggingFaceEmbeddings
5
  from groq import Groq
6
 
7
+ # Path FAISS index
8
+ faiss_path = "faiss_index"
9
+
10
+ # Pastikan file FAISS index ada sebelum loading
11
+ if not os.path.exists(f"{faiss_path}/index.faiss"):
12
+ raise FileNotFoundError(f"⚠️ File FAISS index tidak ditemukan di {faiss_path}. Pastikan Anda telah membuat dan mengunggahnya!")
13
+
14
+ # Load FAISS index
15
  vector_store = FAISS.load_local(
16
+ faiss_path,
17
  HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-L6-v2"),
18
+ allow_dangerous_deserialization=True
19
  )
20
 
21
  # Load API Key dari variabel lingkungan
22
+ GROQ_API_KEY = os.getenv("GROQ_API_KEY")
23
  if not GROQ_API_KEY:
24
  raise ValueError("⚠️ API Key Groq tidak ditemukan! Setel variabel lingkungan 'GROQ_API_KEY'.")
25