PeterPinetree commited on
Commit
d21b9af
·
verified ·
1 Parent(s): 6040209

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -4
app.py CHANGED
@@ -3,6 +3,10 @@ import os
3
  from huggingface_hub import InferenceClient
4
  import random
5
  from typing import Generator, Dict, List, Tuple, Optional
 
 
 
 
6
 
7
  # Get token from environment variable
8
  hf_token = os.environ.get("HF_TOKEN")
@@ -11,10 +15,10 @@ client = InferenceClient("HuggingFaceH4/zephyr-7b-beta", token=hf_token)
11
  # Story genres with genre-specific example prompts
12
  GENRE_EXAMPLES = {
13
  "fairy tale": [
14
- "I follow the shimmer of fairy dust into a hidden forest"
15
- "I meet a talking rabbit who claims to know a secret about the kings lost crown"
16
- "A tiny dragon appears at my window, asking for help to find its mother"
17
- "I step into a clearing where the trees whisper ancient riddles"
18
  "A friendly witch invites me into her cozy cottage, offering a warm cup of tea"
19
  ],
20
  "fantasy": [
@@ -175,6 +179,7 @@ def respond(
175
 
176
  except Exception as e:
177
  error_msg = f"Story magic temporarily interrupted. Please try again. (Error: {str(e)})"
 
178
  return "", chat_history + [(message, error_msg)]
179
 
180
  def save_story(chat_history):
 
3
  from huggingface_hub import InferenceClient
4
  import random
5
  from typing import Generator, Dict, List, Tuple, Optional
6
+ import logging # Added logging for better debugging
7
+
8
+ # Configure logging
9
+ logging.basicConfig(level=logging.ERROR, format='%(asctime)s - %(levelname)s - %(message)s')
10
 
11
  # Get token from environment variable
12
  hf_token = os.environ.get("HF_TOKEN")
 
15
  # Story genres with genre-specific example prompts
16
  GENRE_EXAMPLES = {
17
  "fairy tale": [
18
+ "I follow the shimmer of fairy dust into a hidden forest",
19
+ "I meet a talking rabbit who claims to know a secret about the king's lost crown",
20
+ "A tiny dragon appears at my window, asking for help to find its mother",
21
+ "I step into a clearing where the trees whisper ancient riddles",
22
  "A friendly witch invites me into her cozy cottage, offering a warm cup of tea"
23
  ],
24
  "fantasy": [
 
179
 
180
  except Exception as e:
181
  error_msg = f"Story magic temporarily interrupted. Please try again. (Error: {str(e)})"
182
+ logging.error("Error in respond function", exc_info=True) # Added logging
183
  return "", chat_history + [(message, error_msg)]
184
 
185
  def save_story(chat_history):