Update app.py
Browse files6 unmodified lines78910111213141516171819202122232425262728291 unmodified line313233343536376 unmodified lines# Global datasets - load lazilymath_samples = Nonedef load_datasets_lazy():"""Load datasets only when needed - prevents startup crashes"""global math_samplesif math_samples is not None:return math_samplesprint("🔄 Loading datasets...")try:gsm8k = load_dataset("openai/gsm8k", "main", streaming=True)samples = []for i, item in enumerate(gsm8k["train"]):samples.append(item["question"])if i >= 50:breakprint(f"✅ Loaded {len(samples)} GSM8K samples")math_samples = samplesreturn samplesexcept Exception as e:print(f"⚠️ Dataset error: {e}, using fallback")math_samples = [1 unmodified line"A triangle has sides of length 5, 12, and 13. What is its area?","If log₂(x) + log₂(x+6) = 4, find the value of x.","Find the limit: lim(x->0) (sin(x)/x)","Solve the system: x + 2y = 7, 3x - y = 4"]return math_samples6 unmodified lines78910111213141516171819202122232425262728293031323334353637383940414243444546474849505152531 unmodified line5556575859606162636 unmodified lines# Global datasets - load lazilymath_samples = Nonedef load_sample_problems():"""Load sample problems from ALL datasets"""global math_samplesif math_samples is not None:return math_samplessamples = []try:# GSM8K (math problems)gsm8k = load_dataset("openai/gsm8k", "main", streaming=True)for i, item in enumerate(gsm8k["train"]):samples.append(item["question"])if i >= 50:break# Fineweb-edu (educational text - extract math-like questions)fw = load_dataset("HuggingFaceFW/fineweb-edu", name="sample-10BT", split="train", streaming=True)fw_count = 0for item in fw:# Filter for math-related content (simple keyword match)if any(word in item['text'].lower() for word in ['math', 'calculate', 'solve', 'derivative', 'integral', 'triangle', 'equation']):samples.append(item['text'][:200] + " (Solve this math problem.)") # Truncate for brevityfw_count += 1if fw_count >= 20:break# Ultrachat_200k (chat-like math queries)ds = load_dataset("HuggingFaceH4/ultrachat_200k", streaming=True)ds_count = 0for item in ds:if 'math' in item['messages'][0]['content'].lower() or 'calculate' in item['messages'][0]['content'].lower():user_msg = item['messages'][0]['content']samples.append(user_msg)ds_count += 1if ds_count >= 20:breakprint(f"✅ Loaded {len(samples)} samples: GSM8K ({50}), Fineweb-edu ({fw_count}), Ultrachat ({ds_count})")math_samples = samplesreturn samplesexcept Exception as e:print(f"⚠️ Dataset error: {e}, using fallback")math_samples = [1 unmodified line"A triangle has sides of length 5, 12, and 13. What is its area?","If log₂(x) + log₂(x+6) = 4, find the value of x.","Find the limit: lim(x->0) (sin(x)/x)","Solve the system: x + 2y = 7, 3x - y = 4","Calculate the integral of sin(x) from 0 to pi.","What is the probability of rolling a 6 on a die 3 times in a row?"]return math_samples
app.py+32-6