AEUPH commited on
Commit
62c045c
·
verified ·
1 Parent(s): 1df195d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -31
app.py CHANGED
@@ -71,7 +71,7 @@ class TemporalPredictionSystem:
71
  self.self_model_accuracy = 0.2 # Starts low, improves with conversation
72
  self.model_growth_rate = 0
73
  self.total_interactions = 0
74
-
75
  # Response generators
76
  self.response_templates = [
77
  "Based on your current trajectory, I see {{future}}.",
@@ -108,38 +108,53 @@ class TemporalPredictionSystem:
108
  self.fetch_quotes_data()
109
 
110
  def fetch_quotes_data(self):
111
- """Fetch quotes data from Hugging Face dataset API"""
112
- try:
113
- response = requests.get(
114
- "https://datasets-server.huggingface.co/rows?dataset=Abirate%2Fenglish_quotes&config=default&split=train&offset=0&length=100"
115
- )
116
- data = response.json()
117
-
118
- if data and "rows" in data:
119
- for row in data["rows"]:
120
- if row and "row" in row and "quote" in row["row"]:
121
- quote = row["row"]["quote"]
122
- self.quotes_data.append(quote)
123
- words = [w for w in re.sub(r'[^\w\s]', '', quote.lower()).split() if len(w) > 3]
124
- self.word_corpus = list(set(self.word_corpus + words))
125
- if "tags" in row["row"]:
126
- tags = [row["row"]["tags"]] if not isinstance(row["row"]["tags"], list) else row["row"]["tags"]
127
- self.tags_data.extend(tags)
128
- tag_words = [tag.lower() for tag in tags if len(tag) > 3]
129
- self.word_corpus = list(set(self.word_corpus + tag_words))
130
-
131
- print(f"Loaded {len(self.quotes_data)} quotes and {len(self.tags_data)} tags")
132
- print(f"Word corpus expanded to {len(self.word_corpus)} words")
133
- for word in self.word_corpus:
134
- self.topic_extractor[word] = 1
135
- self.topic_relations[word] = []
136
- self.build_initial_markov_chain()
137
-
138
- except Exception as e:
139
- print(f"Error fetching quotes data: {e}")
 
 
 
 
 
140
  self.build_initial_markov_chain()
 
 
 
 
 
 
 
 
 
 
 
141
 
142
- self.initialize()
143
 
144
  def build_initial_markov_chain(self):
145
  """Build a Markov chain from quotes and corpus data"""
 
71
  self.self_model_accuracy = 0.2 # Starts low, improves with conversation
72
  self.model_growth_rate = 0
73
  self.total_interactions = 0
74
+ self.quote_offset = 0
75
  # Response generators
76
  self.response_templates = [
77
  "Based on your current trajectory, I see {{future}}.",
 
108
  self.fetch_quotes_data()
109
 
110
  def fetch_quotes_data(self):
111
+ """Fetch quotes data from HuggingFace dataset API with dynamic offset for continuous expansion."""
112
+ try:
113
+ url = f"https://datasets-server.huggingface.co/rows?dataset=Abirate%2Fenglish_quotes&config=default&split=train&offset={self.quote_offset}&length=100"
114
+ response = requests.get(url)
115
+ data = response.json()
116
+
117
+ if data and "rows" in data:
118
+ for row in data["rows"]:
119
+ if row and "row" in row and "quote" in row["row"]:
120
+ quote = row["row"]["quote"]
121
+ self.quotes_data.append(quote)
122
+
123
+ # Process quote into words for corpus
124
+ words = [w for w in re.sub(r'[^\w\s]', '', quote.lower()).split() if len(w) > 3]
125
+ self.word_corpus = list(set(self.word_corpus + words))
126
+
127
+ # Extract tags if available
128
+ if "tags" in row["row"]:
129
+ tags = [row["row"]["tags"]] if not isinstance(row["row"]["tags"], list) else row["row"]["tags"]
130
+ self.tags_data.extend(tags)
131
+
132
+ # Add tags to corpus
133
+ tag_words = [tag.lower() for tag in tags if len(tag) > 3]
134
+ self.word_corpus = list(set(self.word_corpus + tag_words))
135
+
136
+ print(f"Loaded {len(self.quotes_data)} quotes and {len(self.tags_data)} tags")
137
+ print(f"Word corpus expanded to {len(self.word_corpus)} words")
138
+
139
+ # Initialize topic extractor with corpus
140
+ for word in self.word_corpus:
141
+ self.topic_extractor[word] = 1
142
+ self.topic_relations[word] = []
143
+
144
+ # Build Markov chain
145
  self.build_initial_markov_chain()
146
+
147
+ # Increment the offset for next iteration to load additional quotes
148
+ self.quote_offset += 100
149
+
150
+ except Exception as e:
151
+ print(f"Error fetching quotes data: {e}")
152
+ # Build the Markov chain with default corpus if fetch fails
153
+ self.build_initial_markov_chain()
154
+
155
+ # Initialize the system (or reinitialize if desired)
156
+ self.initialize()
157
 
 
158
 
159
  def build_initial_markov_chain(self):
160
  """Build a Markov chain from quotes and corpus data"""