Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -121,41 +121,39 @@ class TemporalPredictionSystem:
|
|
| 121 |
if row and "row" in row and "quote" in row["row"]:
|
| 122 |
quote = row["row"]["quote"]
|
| 123 |
self.quotes_data.append(quote)
|
| 124 |
-
|
| 125 |
# Process quote into words for corpus
|
| 126 |
words = [w for w in re.sub(r'[^\w\s]', '', quote.lower()).split() if len(w) > 3]
|
| 127 |
self.word_corpus = list(set(self.word_corpus + words))
|
| 128 |
-
|
| 129 |
# Extract tags if available
|
| 130 |
if "tags" in row["row"]:
|
| 131 |
-
tags =
|
| 132 |
self.tags_data.extend(tags)
|
| 133 |
-
|
| 134 |
# Add tags to corpus
|
| 135 |
tag_words = [tag.lower() for tag in tags if len(tag) > 3]
|
| 136 |
self.word_corpus = list(set(self.word_corpus + tag_words))
|
| 137 |
-
|
| 138 |
print(f"Loaded {len(self.quotes_data)} quotes and {len(self.tags_data)} tags")
|
| 139 |
print(f"Word corpus expanded to {len(self.word_corpus)} words")
|
| 140 |
-
|
| 141 |
-
#
|
| 142 |
for word in self.word_corpus:
|
| 143 |
-
self.topic_extractor
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
|
|
|
| 147 |
self.build_initial_markov_chain()
|
| 148 |
-
|
| 149 |
# Increment the offset for next iteration to load additional quotes
|
| 150 |
self.quote_offset += 100
|
| 151 |
-
|
| 152 |
except Exception as e:
|
| 153 |
print(f"Error fetching quotes data: {e}")
|
| 154 |
-
#
|
| 155 |
self.build_initial_markov_chain()
|
| 156 |
-
|
| 157 |
-
# Initialize the system (or reinitialize if desired)
|
| 158 |
-
self.initialize()
|
| 159 |
|
| 160 |
|
| 161 |
def build_initial_markov_chain(self):
|
|
|
|
| 121 |
if row and "row" in row and "quote" in row["row"]:
|
| 122 |
quote = row["row"]["quote"]
|
| 123 |
self.quotes_data.append(quote)
|
| 124 |
+
|
| 125 |
# Process quote into words for corpus
|
| 126 |
words = [w for w in re.sub(r'[^\w\s]', '', quote.lower()).split() if len(w) > 3]
|
| 127 |
self.word_corpus = list(set(self.word_corpus + words))
|
| 128 |
+
|
| 129 |
# Extract tags if available
|
| 130 |
if "tags" in row["row"]:
|
| 131 |
+
tags = row["row"]["tags"] if isinstance(row["row"]["tags"], list) else [row["row"]["tags"]]
|
| 132 |
self.tags_data.extend(tags)
|
| 133 |
+
|
| 134 |
# Add tags to corpus
|
| 135 |
tag_words = [tag.lower() for tag in tags if len(tag) > 3]
|
| 136 |
self.word_corpus = list(set(self.word_corpus + tag_words))
|
| 137 |
+
|
| 138 |
print(f"Loaded {len(self.quotes_data)} quotes and {len(self.tags_data)} tags")
|
| 139 |
print(f"Word corpus expanded to {len(self.word_corpus)} words")
|
| 140 |
+
|
| 141 |
+
# Update topic extractor with any new words
|
| 142 |
for word in self.word_corpus:
|
| 143 |
+
if word not in self.topic_extractor:
|
| 144 |
+
self.topic_extractor[word] = 1
|
| 145 |
+
self.topic_relations[word] = []
|
| 146 |
+
|
| 147 |
+
# Rebuild Markov chain to include new quotes and tags
|
| 148 |
self.build_initial_markov_chain()
|
| 149 |
+
|
| 150 |
# Increment the offset for next iteration to load additional quotes
|
| 151 |
self.quote_offset += 100
|
| 152 |
+
|
| 153 |
except Exception as e:
|
| 154 |
print(f"Error fetching quotes data: {e}")
|
| 155 |
+
# Rebuild the Markov chain with current corpus if fetch fails
|
| 156 |
self.build_initial_markov_chain()
|
|
|
|
|
|
|
|
|
|
| 157 |
|
| 158 |
|
| 159 |
def build_initial_markov_chain(self):
|