Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -7,7 +7,7 @@ import nltk
|
|
| 7 |
|
| 8 |
# --- 1. SETUP MODELS AND DATABASE ---
|
| 9 |
|
| 10 |
-
#
|
| 11 |
print("Downloading NLTK's 'punkt' model...")
|
| 12 |
nltk.download('punkt')
|
| 13 |
|
|
@@ -24,15 +24,23 @@ print("ChromaDB collection ready.")
|
|
| 24 |
# --- 2. CORE FUNCTIONS ---
|
| 25 |
def index_transcript(transcript_text):
|
| 26 |
"""Chunks and indexes a full transcript into ChromaDB."""
|
| 27 |
-
print("--- DEBUGGING ---")
|
| 28 |
-
print(f"Raw transcript received: '{transcript_text}'")
|
| 29 |
-
|
| 30 |
if not transcript_text.strip():
|
| 31 |
return "Please paste a transcript before indexing.", pd.DataFrame()
|
| 32 |
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
chunks = [chunk.strip() for chunk in chunks if len(chunk.strip()) > 5]
|
| 35 |
|
|
|
|
|
|
|
| 36 |
print(f"Number of chunks created: {len(chunks)}")
|
| 37 |
print(f"Chunks found: {chunks}")
|
| 38 |
print("--- END DEBUGGING ---")
|
|
@@ -62,7 +70,7 @@ def search_transcript(query):
|
|
| 62 |
})
|
| 63 |
return df, "Search complete."
|
| 64 |
|
| 65 |
-
# --- 3. GRADIO INTERFACE ---
|
| 66 |
sample_transcript = """Atendente: Olá, bem-vindo à EletroMax. Meu nome é Sofia, em que posso ajudar?
|
| 67 |
Cliente: Oi, Sofia. Eu comprei uma cafeteira no site de vocês na semana passada, e ela simplesmente parou de funcionar.
|
| 68 |
Atendente: Puxa, que chato isso. Sinto muito pelo transtorno. Pode me informar o número do pedido para eu localizar sua compra?
|
|
|
|
| 7 |
|
| 8 |
# --- 1. SETUP MODELS AND DATABASE ---
|
| 9 |
|
| 10 |
+
# This single download is all we need.
|
| 11 |
print("Downloading NLTK's 'punkt' model...")
|
| 12 |
nltk.download('punkt')
|
| 13 |
|
|
|
|
| 24 |
# --- 2. CORE FUNCTIONS ---
|
| 25 |
def index_transcript(transcript_text):
|
| 26 |
"""Chunks and indexes a full transcript into ChromaDB."""
|
|
|
|
|
|
|
|
|
|
| 27 |
if not transcript_text.strip():
|
| 28 |
return "Please paste a transcript before indexing.", pd.DataFrame()
|
| 29 |
|
| 30 |
+
# --- FIX: Explicitly load the Portuguese tokenizer to avoid lookup errors ---
|
| 31 |
+
# This file is included in the 'punkt' download.
|
| 32 |
+
try:
|
| 33 |
+
pt_tokenizer = nltk.data.load('tokenizers/punkt/portuguese.pickle')
|
| 34 |
+
chunks = pt_tokenizer.tokenize(transcript_text)
|
| 35 |
+
except Exception as e:
|
| 36 |
+
# Fallback to default tokenizer if the Portuguese one fails for any reason
|
| 37 |
+
print(f"Could not load Portuguese tokenizer, falling back to default. Error: {e}")
|
| 38 |
+
chunks = nltk.sent_tokenize(transcript_text)
|
| 39 |
+
|
| 40 |
chunks = [chunk.strip() for chunk in chunks if len(chunk.strip()) > 5]
|
| 41 |
|
| 42 |
+
# Debugging logs to confirm the chunking
|
| 43 |
+
print("--- CHUNKING DEBUG ---")
|
| 44 |
print(f"Number of chunks created: {len(chunks)}")
|
| 45 |
print(f"Chunks found: {chunks}")
|
| 46 |
print("--- END DEBUGGING ---")
|
|
|
|
| 70 |
})
|
| 71 |
return df, "Search complete."
|
| 72 |
|
| 73 |
+
# --- 3. GRADIO INTERFACE (No changes) ---
|
| 74 |
sample_transcript = """Atendente: Olá, bem-vindo à EletroMax. Meu nome é Sofia, em que posso ajudar?
|
| 75 |
Cliente: Oi, Sofia. Eu comprei uma cafeteira no site de vocês na semana passada, e ela simplesmente parou de funcionar.
|
| 76 |
Atendente: Puxa, que chato isso. Sinto muito pelo transtorno. Pode me informar o número do pedido para eu localizar sua compra?
|