niddijoris commited on
Commit
7d80464
Β·
verified Β·
1 Parent(s): d10f0b0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -10
app.py CHANGED
@@ -10,17 +10,32 @@ load_dotenv()
10
  st.set_page_config(page_title="Customer Support AI", page_icon="πŸ€–")
11
 
12
 
13
- with st.spinner("Updating knowledge base..."):
14
- try:
15
-
16
- if not os.path.exists("./chroma_db"):
17
- st.info("Vector database not found. Starting ingestion...")
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  run_ingestion()
19
- st.success("Ingestion complete!")
20
- else:
21
- st.write("Database already exists.")
22
- except Exception as e:
23
- st.error(f"Ingestion failed: {e}")
 
 
24
 
25
  st.title("πŸ€– TechFlow Support Agent")
26
 
 
10
  st.set_page_config(page_title="Customer Support AI", page_icon="πŸ€–")
11
 
12
 
13
+ # To'g'ri yo'llarni belgilaymiz
14
+ BASE_DIR = os.path.dirname(os.path.abspath(__file__))
15
+ DB_PATH = os.path.join(BASE_DIR, "vector_db") # Ingest.py dagi bilan bir xil bo'lishi shart
16
+ DATA_PATH = os.path.join(BASE_DIR, "data")
17
+
18
+ st.sidebar.write("### Tizim holati:")
19
+
20
+ # 1. Avval 'data' papkasida PDF-lar borligini tekshiramiz
21
+ if not os.path.exists(DATA_PATH) or not os.listdir(DATA_PATH):
22
+ st.sidebar.error("❌ 'data/' papkasida PDF fayllar topilmadi!")
23
+ else:
24
+ st.sidebar.success(f"πŸ“‚ {len(os.listdir(DATA_PATH))} ta PDF fayl topildi.")
25
+
26
+ # 2. Bazani tekshirish va yaratish (CHROMA emas, VECTOR_DB)
27
+ if not os.path.exists(DB_PATH):
28
+ st.sidebar.warning("⚠️ Baza topilmadi. Ingest boshlanmoqda...")
29
+ with st.spinner("Bilimlar bazasi yaratilmoqda..."):
30
+ try:
31
  run_ingestion()
32
+ st.success("βœ… Ingestion yakunlandi!")
33
+ st.rerun() # Bazani ko'rishi uchun refresh
34
+ except Exception as e:
35
+ st.error(f"❌ Ingestion xatosi: {e}")
36
+ else:
37
+ st.sidebar.success(f"βœ… Baza tayyor: {DB_PATH}")
38
+ st.sidebar.write("Fayllar:", os.listdir(DB_PATH))
39
 
40
  st.title("πŸ€– TechFlow Support Agent")
41