Alimubariz124 commited on
Commit
3b5783e
·
verified ·
1 Parent(s): eae9a85

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -0
app.py CHANGED
@@ -22,23 +22,34 @@ with gr.Blocks() as demo:
22
 
23
  def upload_transcript(file, chunks_state):
24
  try:
 
25
  text = file.read().decode("utf-8")
26
  if not text.strip():
27
  return "Error: Uploaded file is empty.", None, []
28
 
 
 
 
 
 
 
29
  chunks = chunk_text(text)
30
  if not chunks:
31
  return "Error: No chunks generated from the transcript.", None, []
32
 
 
33
  embeddings, chunks = embed_chunks(chunks, embedder)
34
  if embeddings.size == 0:
35
  return "Error: Failed to generate embeddings.", None, []
36
 
 
37
  index = create_faiss_index(embeddings)
38
  return "Transcript uploaded and indexed successfully!", index, chunks
39
  except Exception as e:
40
  return f"Error processing transcript: {str(e)}", None, []
41
 
 
 
42
  def chat_with_transcript(query, index_state, chunks_state):
43
  if index_state is None:
44
  return "Please upload a transcript first."
 
22
 
23
  def upload_transcript(file, chunks_state):
24
  try:
25
+ # Read and decode the file
26
  text = file.read().decode("utf-8")
27
  if not text.strip():
28
  return "Error: Uploaded file is empty.", None, []
29
 
30
+ # Preprocess the transcript
31
+ text = preprocess_transcript(text)
32
+ if not text.strip():
33
+ return "Error: Transcript is empty after preprocessing.", None, []
34
+
35
+ # Chunk the text
36
  chunks = chunk_text(text)
37
  if not chunks:
38
  return "Error: No chunks generated from the transcript.", None, []
39
 
40
+ # Generate embeddings
41
  embeddings, chunks = embed_chunks(chunks, embedder)
42
  if embeddings.size == 0:
43
  return "Error: Failed to generate embeddings.", None, []
44
 
45
+ # Create FAISS index
46
  index = create_faiss_index(embeddings)
47
  return "Transcript uploaded and indexed successfully!", index, chunks
48
  except Exception as e:
49
  return f"Error processing transcript: {str(e)}", None, []
50
 
51
+
52
+
53
  def chat_with_transcript(query, index_state, chunks_state):
54
  if index_state is None:
55
  return "Please upload a transcript first."