Spaces:
Sleeping
Sleeping
looker01202
commited on
Commit
·
99b3f8f
1
Parent(s):
1f36500
Gemini changes added 3
Browse files
app.py
CHANGED
@@ -195,9 +195,57 @@ def chat(message, history, hotel_id):
|
|
195 |
# Final yield with assistant reply
|
196 |
yield ui_history, "" # Update chat, keep textbox cleared
|
197 |
|
198 |
-
# Available hotels
|
199 |
-
hotel_ids = ["cyprus-guesthouse-family", "coastal-villa-family", "village-inn-family"]
|
200 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
201 |
# Gradio UI
|
202 |
with gr.Blocks() as demo:
|
203 |
with gr.Column(variant="panel"):
|
@@ -205,9 +253,10 @@ with gr.Blocks() as demo:
|
|
205 |
gr.Markdown(f"**Running:** {model_name}")
|
206 |
|
207 |
hotel_selector = gr.Dropdown(
|
208 |
-
|
209 |
label="Hotel",
|
210 |
-
value=
|
|
|
211 |
)
|
212 |
|
213 |
with gr.Row():
|
|
|
195 |
# Final yield with assistant reply
|
196 |
yield ui_history, "" # Update chat, keep textbox cleared
|
197 |
|
|
|
|
|
198 |
|
199 |
+
# --- Start: Dynamic Hotel ID Detection ---
|
200 |
+
knowledge_dir = "knowledge"
|
201 |
+
available_hotels = []
|
202 |
+
|
203 |
+
# Check if the knowledge directory exists and is a directory
|
204 |
+
if os.path.isdir(knowledge_dir):
|
205 |
+
potential_ids = set()
|
206 |
+
# First pass: collect all potential base names from .txt files
|
207 |
+
for filename in os.listdir(knowledge_dir):
|
208 |
+
if filename.endswith(".txt") and not filename.startswith('.'): # Ignore hidden files
|
209 |
+
if filename.endswith("-system.txt"):
|
210 |
+
# Extract base name from system prompt file
|
211 |
+
base_name = filename[:-len("-system.txt")]
|
212 |
+
else:
|
213 |
+
# Extract base name from main knowledge file
|
214 |
+
base_name = filename[:-len(".txt")]
|
215 |
+
|
216 |
+
if base_name: # Ensure we got a non-empty base name
|
217 |
+
potential_ids.add(base_name)
|
218 |
+
|
219 |
+
# Second pass: check if both files exist for each potential ID
|
220 |
+
# Sort the potential IDs for consistent dropdown order
|
221 |
+
for hotel_id in sorted(list(potential_ids)):
|
222 |
+
main_file = os.path.join(knowledge_dir, f"{hotel_id}.txt")
|
223 |
+
system_file = os.path.join(knowledge_dir, f"{hotel_id}-system.txt")
|
224 |
+
|
225 |
+
# Check if BOTH the main knowledge file AND the system prompt file exist
|
226 |
+
if os.path.exists(main_file) and os.path.exists(system_file):
|
227 |
+
available_hotels.append(hotel_id)
|
228 |
+
print(f"✅ Found valid hotel pair: {hotel_id}")
|
229 |
+
else:
|
230 |
+
# Optional: Print a warning if one file exists but not the other
|
231 |
+
if os.path.exists(main_file) or os.path.exists(system_file):
|
232 |
+
print(f"⚠️ Skipping '{hotel_id}': Missing either '{hotel_id}.txt' or '{hotel_id}-system.txt'")
|
233 |
+
|
234 |
+
else:
|
235 |
+
print(f"❌ Error: Knowledge directory '{knowledge_dir}' not found or is not a directory.")
|
236 |
+
|
237 |
+
# Handle case where no valid hotels were found
|
238 |
+
if not available_hotels:
|
239 |
+
print("🚨 CRITICAL: No valid hotels found in the knowledge directory. The dropdown will be empty.")
|
240 |
+
# You might want to add a placeholder or handle this error more gracefully
|
241 |
+
# For now, the dropdown will just be empty or disabled.
|
242 |
+
# --- End: Dynamic Hotel ID Detection ---
|
243 |
+
|
244 |
+
# --- The above dynamic detection replaces the old hardcoded list ---
|
245 |
+
# hotel_ids = ["cyprus-guesthouse-family", "coastal-villa-family", "village-inn-family"] # Remove or comment out this line
|
246 |
+
|
247 |
+
|
248 |
+
# Gradio UI
|
249 |
# Gradio UI
|
250 |
with gr.Blocks() as demo:
|
251 |
with gr.Column(variant="panel"):
|
|
|
253 |
gr.Markdown(f"**Running:** {model_name}")
|
254 |
|
255 |
hotel_selector = gr.Dropdown(
|
256 |
+
choices=available_hotels, # Use the dynamically generated list
|
257 |
label="Hotel",
|
258 |
+
value=available_hotels[0] if available_hotels else None, # Set default to first found hotel, or None if empty
|
259 |
+
interactive=bool(available_hotels) # Disable dropdown if no hotels are found
|
260 |
)
|
261 |
|
262 |
with gr.Row():
|