Spaces:
Runtime error
Runtime error
Update app.py
Browse files325 unmodified lines3263273283293303313323333341 unmodified line33633733833934034134234334434534634734834935035135235335435535635735835936036136217 unmodified lines380381382383384385386325 unmodified linestexts = [clean_arabic_text(poem) for poem in group['poem'].dropna()]all_emotions = []# Enhanced embedding generationembeddings = []for i, text in enumerate(texts):text_chunks = [text[i:i+512] for i in range(0, len(text), 512)]chunk_embeddings = []1 unmodified linechunk_embedding = get_embedding_for_text(chunk, bert_tokenizer, bert_model)chunk_embeddings.append(chunk_embedding)full_embedding = np.mean(chunk_embeddings, axis=0)embeddings.append(full_embedding)progress = (i + 1) / len(texts) * 0.4progress_bar.progress(progress, text=f"Generated embeddings for {i+1}/{len(texts)} poems...")embeddings = np.array(embeddings)# Process emotions with proper chunkingfor i, text in enumerate(texts):text_chunks = [text[i:i+512] for i in range(0, len(text), 512)]chunk_emotions = []for chunk in text_chunks:emotion = emotion_classifier(chunk)[0]['label']chunk_emotions.append(emotion)# Use most common emotion for the full textfinal_emotion = max(set(chunk_emotions), key=chunk_emotions.count)all_emotions.append(final_emotion)progress = 0.4 + ((i + 1) / len(texts) * 0.3)progress_bar.progress(progress, text=f"Classified emotions for {i+1}/{len(texts)} poems...")17 unmodified linesreturn summaries, topic_modeltry:bert_tokenizer, bert_model, emotion_classifier = load_models()st.success("Models loaded successfully!")325 unmodified lines3263273283293303313323333343351 unmodified line33733833934034134234334434534634734834935035135235335435535617 unmodified lines374375376377378379325 unmodified linestexts = [clean_arabic_text(poem) for poem in group['poem'].dropna()]all_emotions = []# Get embeddings with proper output handlingembeddings = []for i, text in enumerate(texts):# Split text into chunks that respect the 512 token limittext_chunks = [text[i:i+512] for i in range(0, len(text), 512)]chunk_embeddings = []1 unmodified linechunk_embedding = get_embedding_for_text(chunk, bert_tokenizer, bert_model)chunk_embeddings.append(chunk_embedding)# Combine chunk embeddings to represent the full poemfull_embedding = np.mean(chunk_embeddings, axis=0)embeddings.append(full_embedding)progress = (i + 1) / len(texts) * 0.4progress_bar.progress(progress, text=f"Generated embeddings for {i+1}/{len(texts)} poems...")embeddings = np.array(embeddings)# Process emotions with tuple output handlingfor i, text in enumerate(texts):result = emotion_classifier(text)emotion = result[0] # Access first element of tupleall_emotions.append(emotion)progress = 0.4 + ((i + 1) / len(texts) * 0.3)progress_bar.progress(progress, text=f"Classified emotions for {i+1}/{len(texts)} poems...")17 unmodified linesreturn summaries, topic_modeltry:bert_tokenizer, bert_model, emotion_classifier = load_models()st.success("Models loaded successfully!")
app.py+8-15