Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -6,8 +6,10 @@ import faiss
|
|
6 |
from sentence_transformers import SentenceTransformer
|
7 |
from datasets import load_dataset
|
8 |
from dotenv import load_dotenv
|
9 |
-
import
|
10 |
-
|
|
|
|
|
11 |
|
12 |
# Load environment variables
|
13 |
load_dotenv()
|
@@ -19,6 +21,10 @@ DATASET_NAME = "midrees2806/7K_Dataset"
|
|
19 |
CHUNK_SIZE = 500
|
20 |
TOP_K = 3
|
21 |
|
|
|
|
|
|
|
|
|
22 |
class GeminiRAGSystem:
|
23 |
def __init__(self):
|
24 |
self.index = None
|
@@ -37,11 +43,11 @@ class GeminiRAGSystem:
|
|
37 |
if self.gemini_api_key:
|
38 |
genai.configure(api_key=self.gemini_api_key)
|
39 |
|
40 |
-
#
|
41 |
self.load_dataset()
|
42 |
|
43 |
def load_dataset(self):
|
44 |
-
"""Load dataset synchronously"""
|
45 |
try:
|
46 |
# Load dataset directly
|
47 |
dataset = load_dataset(
|
@@ -94,9 +100,9 @@ class GeminiRAGSystem:
|
|
94 |
if not self.dataset_loaded:
|
95 |
if self.loading_error:
|
96 |
return f"⚠️ Dataset loading failed: {self.loading_error}"
|
97 |
-
return "⚠️
|
98 |
if not self.gemini_api_key:
|
99 |
-
return "🔑
|
100 |
|
101 |
context = self.get_relevant_context(query)
|
102 |
if not context:
|
@@ -128,7 +134,6 @@ with gr.Blocks(title="UE Chatbot") as app:
|
|
128 |
with gr.Row():
|
129 |
chatbot = gr.Chatbot(
|
130 |
height=500,
|
131 |
-
avatar_images=(None, (None, "https://huggingface.co/spaces/groq/Groq-LLM/resolve/main/groq_logo.png")),
|
132 |
bubble_full_width=False
|
133 |
)
|
134 |
|
@@ -146,7 +151,7 @@ with gr.Blocks(title="UE Chatbot") as app:
|
|
146 |
# Status indicator
|
147 |
status = gr.Textbox(
|
148 |
label="System Status",
|
149 |
-
value="
|
150 |
interactive=False
|
151 |
)
|
152 |
|
|
|
6 |
from sentence_transformers import SentenceTransformer
|
7 |
from datasets import load_dataset
|
8 |
from dotenv import load_dotenv
|
9 |
+
import warnings
|
10 |
+
|
11 |
+
# Suppress warnings
|
12 |
+
warnings.filterwarnings("ignore")
|
13 |
|
14 |
# Load environment variables
|
15 |
load_dotenv()
|
|
|
21 |
CHUNK_SIZE = 500
|
22 |
TOP_K = 3
|
23 |
|
24 |
+
# Workaround for huggingface_hub compatibility
|
25 |
+
import huggingface_hub
|
26 |
+
huggingface_hub.__version__ = "0.13.4"
|
27 |
+
|
28 |
class GeminiRAGSystem:
|
29 |
def __init__(self):
|
30 |
self.index = None
|
|
|
43 |
if self.gemini_api_key:
|
44 |
genai.configure(api_key=self.gemini_api_key)
|
45 |
|
46 |
+
# Load dataset
|
47 |
self.load_dataset()
|
48 |
|
49 |
def load_dataset(self):
|
50 |
+
"""Load dataset synchronously with error handling"""
|
51 |
try:
|
52 |
# Load dataset directly
|
53 |
dataset = load_dataset(
|
|
|
100 |
if not self.dataset_loaded:
|
101 |
if self.loading_error:
|
102 |
return f"⚠️ Dataset loading failed: {self.loading_error}"
|
103 |
+
return "⚠️ System initialization in progress..."
|
104 |
if not self.gemini_api_key:
|
105 |
+
return "🔑 API key not configured"
|
106 |
|
107 |
context = self.get_relevant_context(query)
|
108 |
if not context:
|
|
|
134 |
with gr.Row():
|
135 |
chatbot = gr.Chatbot(
|
136 |
height=500,
|
|
|
137 |
bubble_full_width=False
|
138 |
)
|
139 |
|
|
|
151 |
# Status indicator
|
152 |
status = gr.Textbox(
|
153 |
label="System Status",
|
154 |
+
value="Ready" if rag_system.dataset_loaded else f"Initializing... {rag_system.loading_error or ''}",
|
155 |
interactive=False
|
156 |
)
|
157 |
|