botsi commited on
Commit
e9d44a7
·
verified ·
1 Parent(s): 95a3c67

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -49
app.py CHANGED
@@ -145,6 +145,56 @@ def construct_input_prompt(chat_history, message, personalized_data):
145
 
146
  return input_prompt
147
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148
  ## trust-game-llama-2-7b-chat
149
  # app.py
150
  @spaces.GPU
@@ -159,12 +209,12 @@ def generate(
159
  repetition_penalty: float = 1.2,
160
  ) -> Iterator[str]: # Change return type hint to Iterator[str]
161
 
 
162
  # Fetch personalized data
163
  url_params = get_window_url_params()
164
  session_index = get_session_index(chat_history, url_params)
165
  personalized_data = fetch_personalized_data(session_index)
166
 
167
-
168
  # Construct the input prompt using the functions from the system_prompt_config module
169
  input_prompt = construct_input_prompt(chat_history, message, personalized_data)
170
 
@@ -247,54 +297,6 @@ chat_interface = gr.ChatInterface(
247
  ],
248
  )
249
 
250
- with gr.Blocks(css="style.css") as demo:
251
- #gr.Markdown(DESCRIPTION)
252
- #gr.DuplicateButton(value="Duplicate Space for private use", elem_id="duplicate-button")
253
- ## gradio-chatbot-read-query-param
254
- url_params = gr.JSON({}, visible=False, label="URL Params")
255
-
256
- ## gradio-chatbot-read-query-param
257
- def get_session_index(history, url_params):
258
- personalized_data = None # Initialize with None
259
- if history and bool(history[-1][0].strip()):
260
- session_index = url_params.get('session_index')
261
- print(session_index)
262
- # Fetch personalized data
263
- personalized_data = fetch_personalized_data(session_index)
264
- print(personalized_data)
265
- return personalized_data
266
-
267
- ## trust-game-llama-2-7b-chat
268
- # app.py
269
- def get_default_system_prompt(personalized_data):
270
- #BOS, EOS = "<s>", "</s>"
271
- #BINST, EINST = "[INST]", "[/INST]"
272
- BSYS, ESYS = "<<SYS>>\n", "\n<</SYS>>\n\n"
273
-
274
- DEFAULT_SYSTEM_PROMPT = f""" You are an intelligent and fair game guide in a 2-player trust game, assisting players in making decisions to win.
275
- Answer in a consistent style. Answer per question should be maximum 2 sentences long. The players are called The Investor and The Dealer and keep their role throughout the whole game.
276
- Both start with 10€ in round 1. The game consists of 3 rounds. In round 1, The Investor invests between 0€ and 10€.
277
- This amount is tripled automatically, and The Dealer can then distribute the tripled amount. After that, round 1 is over.
278
- Both go into the next round with their current asset: The Investor with 10€ minus what he invested plus what he received back from The Dealer.
279
- The Dealer with 10€ plus what he kept from the tripled amount.
280
- You will receive a JSON with information on who trusted whom with how much money after each round as context.
281
- Your goal is to guide players through the game, providing clear instructions and explanations.
282
- If any question or action seems unclear, explain it rather than providing inaccurate information.
283
- If you're unsure about an answer, it's better not to guess.
284
-
285
- Example JSON context after a round: {personalized_data}
286
-
287
- Few-shot training examples
288
- {BSYS} Give an overview of the trust game. {ESYS}
289
- {BSYS} Explain how trust amounts are calculated. {ESYS}
290
- {BSYS} What happens if a player doesn't trust in a round? {ESYS}
291
- """
292
- print(DEFAULT_SYSTEM_PROMPT)
293
- return DEFAULT_SYSTEM_PROMPT
294
-
295
- chat_interface.render()
296
- #gr.Markdown(LICENSE)
297
-
298
  if __name__ == "__main__":
299
  #demo.queue(max_size=20).launch()
300
  demo.queue(max_size=20)
 
145
 
146
  return input_prompt
147
 
148
+ with gr.Blocks(css="style.css") as demo:
149
+ #gr.Markdown(DESCRIPTION)
150
+ #gr.DuplicateButton(value="Duplicate Space for private use", elem_id="duplicate-button")
151
+ ## gradio-chatbot-read-query-param
152
+ url_params = gr.JSON({}, visible=False, label="URL Params")
153
+ # Execute the JavaScript function to obtain the URL parameters as a dictionary
154
+ url_params = gr.javascript.execute(url_params)
155
+
156
+ ## gradio-chatbot-read-query-param
157
+ def get_session_index(history, url_params):
158
+ personalized_data = None # Initialize with None
159
+ if history and bool(history[-1][0].strip()):
160
+ session_index = url_params.get('session_index')
161
+ print(session_index)
162
+ # Fetch personalized data
163
+ personalized_data = fetch_personalized_data(session_index)
164
+ print(personalized_data)
165
+ return personalized_data
166
+
167
+ ## trust-game-llama-2-7b-chat
168
+ # app.py
169
+ def get_default_system_prompt(personalized_data):
170
+ #BOS, EOS = "<s>", "</s>"
171
+ #BINST, EINST = "[INST]", "[/INST]"
172
+ BSYS, ESYS = "<<SYS>>\n", "\n<</SYS>>\n\n"
173
+
174
+ DEFAULT_SYSTEM_PROMPT = f""" You are an intelligent and fair game guide in a 2-player trust game, assisting players in making decisions to win.
175
+ Answer in a consistent style. Answer per question should be maximum 2 sentences long. The players are called The Investor and The Dealer and keep their role throughout the whole game.
176
+ Both start with 10€ in round 1. The game consists of 3 rounds. In round 1, The Investor invests between 0€ and 10€.
177
+ This amount is tripled automatically, and The Dealer can then distribute the tripled amount. After that, round 1 is over.
178
+ Both go into the next round with their current asset: The Investor with 10€ minus what he invested plus what he received back from The Dealer.
179
+ The Dealer with 10€ plus what he kept from the tripled amount.
180
+ You will receive a JSON with information on who trusted whom with how much money after each round as context.
181
+ Your goal is to guide players through the game, providing clear instructions and explanations.
182
+ If any question or action seems unclear, explain it rather than providing inaccurate information.
183
+ If you're unsure about an answer, it's better not to guess.
184
+
185
+ Example JSON context after a round: {personalized_data}
186
+
187
+ Few-shot training examples
188
+ {BSYS} Give an overview of the trust game. {ESYS}
189
+ {BSYS} Explain how trust amounts are calculated. {ESYS}
190
+ {BSYS} What happens if a player doesn't trust in a round? {ESYS}
191
+ """
192
+ print(DEFAULT_SYSTEM_PROMPT)
193
+ return DEFAULT_SYSTEM_PROMPT
194
+
195
+ chat_interface.render()
196
+ #gr.Markdown(LICENSE)
197
+
198
  ## trust-game-llama-2-7b-chat
199
  # app.py
200
  @spaces.GPU
 
209
  repetition_penalty: float = 1.2,
210
  ) -> Iterator[str]: # Change return type hint to Iterator[str]
211
 
212
+
213
  # Fetch personalized data
214
  url_params = get_window_url_params()
215
  session_index = get_session_index(chat_history, url_params)
216
  personalized_data = fetch_personalized_data(session_index)
217
 
 
218
  # Construct the input prompt using the functions from the system_prompt_config module
219
  input_prompt = construct_input_prompt(chat_history, message, personalized_data)
220
 
 
297
  ],
298
  )
299
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
300
  if __name__ == "__main__":
301
  #demo.queue(max_size=20).launch()
302
  demo.queue(max_size=20)