awacke1 commited on
Commit
371dba5
·
verified ·
1 Parent(s): 95de190

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -4
app.py CHANGED
@@ -19,25 +19,32 @@ The app uses **DistilGPT-2** to generate creative outlines formatted in Markdown
19
  examples = [
20
  ["The old lighthouse keeper stared into the storm. He'd seen many tempests, but this one was different. This one had eyes..."],
21
  ["In a city powered by dreams, a young inventor creates a machine that can record them. His first recording reveals a nightmare that doesn't belong to him."],
22
- ["The knight adjusted his helmet, the dragon's roar echoing in the valley. He was ready for the fight, but not for what the dragon said when it finally spoke."],
23
  ["She found the old leather-bound journal in her grandfather's attic. The first entry read: 'To relieve stress, I walk in the woods. But today, the woods walked with me.'"],
24
  ["The meditation app promised to help her 'delete unhelpful thoughts.' She tapped the button, and to her horror, the memory of her own name began to fade..."]
25
  ]
26
 
27
  # --- Model Initialization ---
28
- # This section loads a smaller, CPU-friendly model that does not require a token.
 
29
  generator = None
30
  model_error = None
31
 
32
  try:
33
  print("Initializing model... This may take a moment.")
34
 
35
- # Using a smaller, fully open model that does not require authentication.
 
 
 
 
 
36
  generator = pipeline(
37
  "text-generation",
38
  model="distilgpt2",
39
  torch_dtype=torch.float32, # Use float32 for wider CPU compatibility
40
- device_map="auto" # Will use GPU if available, otherwise CPU
 
41
  )
42
  print("✅ DistilGPT-2 model loaded successfully!")
43
 
 
19
  examples = [
20
  ["The old lighthouse keeper stared into the storm. He'd seen many tempests, but this one was different. This one had eyes..."],
21
  ["In a city powered by dreams, a young inventor creates a machine that can record them. His first recording reveals a nightmare that doesn't belong to him."],
22
+ ["The knight adjusted his helmet, the dragon's roar echoing in the valley. He was ready for the fight, but for what the dragon said when it finally spoke."],
23
  ["She found the old leather-bound journal in her grandfather's attic. The first entry read: 'To relieve stress, I walk in the woods. But today, the woods walked with me.'"],
24
  ["The meditation app promised to help her 'delete unhelpful thoughts.' She tapped the button, and to her horror, the memory of her own name began to fade..."]
25
  ]
26
 
27
  # --- Model Initialization ---
28
+ # This section loads a smaller, CPU-friendly model.
29
+ # It will automatically use the HF_TOKEN secret when deployed on Hugging Face Spaces.
30
  generator = None
31
  model_error = None
32
 
33
  try:
34
  print("Initializing model... This may take a moment.")
35
 
36
+ # Explicitly load the token from environment variables (for HF Spaces secrets)
37
+ # This makes the authentication more robust.
38
+ hf_token = os.environ.get("HF_TOKEN", None)
39
+
40
+ # Using a smaller, fully open model. Passing the token explicitly handles
41
+ # environments that might otherwise send invalid credentials.
42
  generator = pipeline(
43
  "text-generation",
44
  model="distilgpt2",
45
  torch_dtype=torch.float32, # Use float32 for wider CPU compatibility
46
+ device_map="auto", # Will use GPU if available, otherwise CPU
47
+ token=hf_token
48
  )
49
  print("✅ DistilGPT-2 model loaded successfully!")
50