Deadmon commited on
Commit
48521ac
·
verified ·
1 Parent(s): 99eb44f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -12
app.py CHANGED
@@ -385,19 +385,23 @@ def get_logs():
385
 
386
  def select_chunk(evt: gr.SelectData):
387
  logger.info(f"Selected chunk raw data: {evt.value}")
388
- # Ensure evt.value is a list and map to chunk_id and text based on headers order
389
- if isinstance(evt.value, list) and len(evt.value) >= 2:
390
- chunk_id = evt.value[0] # First column is chunk_id
391
- text = evt.value[1] # Second column is text
392
- try:
393
- uuid.UUID(chunk_id, version=4) # Validate chunk_id
 
 
 
 
394
  logger.info(f"Selected chunk: {chunk_id}")
395
- return chunk_id, text
396
- except ValueError:
397
- logger.warning(f"Invalid chunk_id selected: {chunk_id}")
398
- return "", "Error: Invalid chunk_id selected"
399
- logger.warning(f"Invalid selection data: {evt.value}")
400
- return "", "Error: Invalid selection data"
401
 
402
  async def edit_cut(chunk_id, start, end):
403
  logger.info(f"edit_cut called with chunk_id: {chunk_id}, start: {start}, end: {end}")
 
385
 
386
  def select_chunk(evt: gr.SelectData):
387
  logger.info(f"Selected chunk raw data: {evt.value}")
388
+ # Handle single chunk_id or list of row data
389
+ chunk_id = evt.value if isinstance(evt.value, str) else (evt.value[0] if isinstance(evt.value, list) and len(evt.value) > 0 else "")
390
+ if not chunk_id:
391
+ logger.warning(f"Invalid selection data: No chunk_id found in {evt.value}")
392
+ return "", "Error: No chunk_id selected"
393
+ try:
394
+ uuid.UUID(chunk_id, version=4) # Validate chunk_id
395
+ memory = ConversationMemory()
396
+ chunk = memory.get_chunk(chunk_id)
397
+ if chunk:
398
  logger.info(f"Selected chunk: {chunk_id}")
399
+ return chunk_id, chunk["text"]
400
+ logger.warning(f"Chunk not found for chunk_id: {chunk_id}")
401
+ return "", "Error: Chunk not found"
402
+ except ValueError:
403
+ logger.warning(f"Invalid chunk_id selected: {chunk_id}")
404
+ return "", "Error: Invalid chunk_id selected"
405
 
406
  async def edit_cut(chunk_id, start, end):
407
  logger.info(f"edit_cut called with chunk_id: {chunk_id}, start: {start}, end: {end}")