Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
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", "
|
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: [
|
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
|
78 |
-
|
79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
134 |
|
135 |
-
|
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
|