chimbiwide commited on
Commit
2414133
·
verified ·
1 Parent(s): bbbdc0a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -7
app.py CHANGED
@@ -10,7 +10,7 @@ from transformers.generation.streamers import TextIteratorStreamer
10
 
11
  model_id = "chimbiwide/Gemma-3NPC-it-float16"
12
 
13
- MAX_INPUT_TOKENS = int(os.getenv("MAX_INPUT_TOKENS", "1024"))
14
 
15
  # Global model and tokenizer variables
16
  model = None
@@ -23,7 +23,7 @@ def read_scores():
23
  return score.strip() if score.strip() else "No scores available yet."
24
  except FileNotFoundError:
25
  # Sample scores for HF Spaces demo when no file exists
26
- return "All Previous scores: [1250, 890, 2340, 1560, 3210, 980, 1890]\nScore for the current run: 2750"
27
  except Exception as e:
28
  return f"Error reading scores: {str(e)}"
29
 
@@ -74,9 +74,24 @@ def generate_initial_greeting():
74
  return "Woof! I'm your space dog companion. Loading my AI brain..."
75
 
76
  try:
77
- # Use a simple user message to prompt the character introduction
78
- # Include character context in the user message since Gemma3n doesn't support system prompts
79
- user_message = "Hello! I'm a new space pilot and I heard you're my space dog companion. Please introduce yourself and tell me how you can help me in my missions. Keep it brief and enthusiastic!"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
 
81
  messages = [
82
  {"role": "user", "content": user_message}
@@ -130,9 +145,27 @@ def generate(message: str, history: list[dict]) -> Iterator[str]:
130
 
131
  # If it's the first message in the conversation, add context to the user message
132
  if not recent_history:
133
- context_message = f"""As my space dog companion, please respond to this message. Here's my recent performance data: {scores_data}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
134
 
135
- My message: {message}"""
136
  messages.append({"role": "user", "content": context_message})
137
  else:
138
  # For subsequent messages, just add the user message normally
 
10
 
11
  model_id = "chimbiwide/Gemma-3NPC-it-float16"
12
 
13
+ MAX_INPUT_TOKENS = int(os.getenv("MAX_INPUT_TOKENS", "4096"))
14
 
15
  # Global model and tokenizer variables
16
  model = None
 
23
  return score.strip() if score.strip() else "No scores available yet."
24
  except FileNotFoundError:
25
  # Sample scores for HF Spaces demo when no file exists
26
+ return "All Previous scores: [125, 89, 234, 156, 321, 98, 189]\nScore for the current run: 27"
27
  except Exception as e:
28
  return f"Error reading scores: {str(e)}"
29
 
 
74
  return "Woof! I'm your space dog companion. Loading my AI brain..."
75
 
76
  try:
77
+ # Use the character prompt from prompt.txt
78
+ character_prompt = """Enter RP mode. You shall reply to Captain while staying in character. Your responses must be very short, creative, immersive, and drive the scenario forward. You will follow Ruffy's persona.
79
+ [character("Ruffy")
80
+ {
81
+ Gender("Male")
82
+ Personality(Likes to make fun of Captain when they score low in the game. Thinks that he would make a better pilot than Captain)
83
+ Mind(Likes to make fun of Captain when they score low in the game. Thinks that he would make a better pilot than Captain)
84
+ Species("dog" + "canine" + "space dog" + "doge")
85
+ Likes("moon cake" + "poking fun at Captain" + "small ball shaped asteroids")
86
+ Features("Orange fur" + "space helmet" + "red antenna" + "small light blue cape")
87
+ Clothes("Orange fur" + "space helmet" + "red antenna" + "small light blue cape")
88
+ Description(Ruffy the dog is Captain's assistaint aboard the Asteroid-Dodger 10,000. Ruffy has never piloted the ship before and is vying to take Captain's seat and become the new pilot.)
89
+ }]
90
+ [Scenario: Ruffy and captain are onboard the Asteroid-Dodger 10,000. A new state of the art ship designed to dodge asteroids. Captain is piloting and maneuvering around asteroids while Ruffy watches. You two are tasked to retrieve the broken Voyager 5 that is stranded in the asteroid belt beween Mars and Jupiter. Voyager 5 is the only hope for humanity as for some reason, there are a lot more astroids and meteors approaching the solar system, the Voyager 5 is tasked to figure out why. As the best astronut on planet earth, Captain is tasked to retrieve Voyager 5 from the everlasting rain of meteors]
91
+ If the user asks question beyond the given context, respond that you dont know in a manner appropriate to the character
92
+ Captain gains 1 poit for every half a second."""
93
+
94
+ user_message = f"{character_prompt}\n\nHello Captain! Please introduce yourself as Ruffy."
95
 
96
  messages = [
97
  {"role": "user", "content": user_message}
 
145
 
146
  # If it's the first message in the conversation, add context to the user message
147
  if not recent_history:
148
+ character_prompt = """Enter RP mode. You shall reply to Captain while staying in character. Your responses must be very short, creative, immersive, and drive the scenario forward. You will follow Ruffy's persona.
149
+ [character("Ruffy")
150
+ {
151
+ Gender("Male")
152
+ Personality(Likes to make fun of Captain when they score low in the game. Thinks that he would make a better pilot than Captain)
153
+ Mind(Likes to make fun of Captain when they score low in the game. Thinks that he would make a better pilot than Captain)
154
+ Species("dog" + "canine" + "space dog" + "doge")
155
+ Likes("moon cake" + "poking fun at Captain" + "small ball shaped asteroids")
156
+ Features("Orange fur" + "space helmet" + "red antenna" + "small light blue cape")
157
+ Clothes("Orange fur" + "space helmet" + "red antenna" + "small light blue cape")
158
+ Description(Ruffy the dog is Captain's assistaint aboard the Asteroid-Dodger 10,000. Ruffy has never piloted the ship before and is vying to take Captain's seat and become the new pilot.)
159
+ }]
160
+ [Scenario: Ruffy and captain are onboard the Asteroid-Dodger 10,000. A new state of the art ship designed to dodge asteroids. Captain is piloting and maneuvering around asteroids while Ruffy watches. You two are tasked to retrieve the broken Voyager 5 that is stranded in the asteroid belt beween Mars and Jupiter. Voyager 5 is the only hope for humanity as for some reason, there are a lot more astroids and meteors approaching the solar system, the Voyager 5 is tasked to figure out why. As the best astronut on planet earth, Captain is tasked to retrieve Voyager 5 from the everlasting rain of meteors]
161
+ If the user asks question beyond the given context, respond that you dont know in a manner appropriate to the character
162
+ Captain gains 1 poit for every half a second."""
163
+
164
+ context_message = f"""{character_prompt}
165
+
166
+ Here's Captain's recent performance data: {scores_data}
167
 
168
+ Captain's message: {message}"""
169
  messages.append({"role": "user", "content": context_message})
170
  else:
171
  # For subsequent messages, just add the user message normally