sqfoo commited on
Commit
ce0d7c6
·
verified ·
1 Parent(s): 85cff9b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -13,7 +13,7 @@ from utils import PROMPT, INPUT_PROMPT, extract_after_final_answer
13
 
14
  # Initialize the HF Inference Client
15
  # It will automatically pick up the HF_TOKEN environment variable if it's set
16
- client = InferenceClient()
17
 
18
  # Define the models we want to use from the Hugging Face Hub
19
  LLM_MODEL = "Qwen/Qwen2.5-7B-Instruct"
@@ -83,7 +83,7 @@ def start_game():
83
  initial_event # sets state_cur
84
  )
85
 
86
- def play_turn(human_response, loc, player, cur, custom_token, request: gr.Request):
87
  """Executes a single turn of the game loop based on user input."""
88
  status = player.get_attribute()
89
  if not human_response.strip():
@@ -115,7 +115,7 @@ def play_turn(human_response, loc, player, cur, custom_token, request: gr.Reques
115
  }
116
  ]
117
  try:
118
- response = client.chat_completion(
119
  model=LLM_MODEL,
120
  messages=messages,
121
  max_tokens=500,
@@ -138,7 +138,7 @@ def play_turn(human_response, loc, player, cur, custom_token, request: gr.Reques
138
  attribute = player.get_attribute()
139
 
140
  # 3. Check for Game Over conditions
141
- if attribute['hp'] <= 0 or attribute['mp'] <= 0:
142
  loc = -1
143
 
144
  cur = EVENTS[loc]
@@ -253,4 +253,4 @@ with gr.Blocks() as demo:
253
  user_input.submit(**turn_config)
254
 
255
  if __name__ == "__main__":
256
- demo.queue().launch(share=True)
 
13
 
14
  # Initialize the HF Inference Client
15
  # It will automatically pick up the HF_TOKEN environment variable if it's set
16
+ client = InferenceClient(timeout=60)
17
 
18
  # Define the models we want to use from the Hugging Face Hub
19
  LLM_MODEL = "Qwen/Qwen2.5-7B-Instruct"
 
83
  initial_event # sets state_cur
84
  )
85
 
86
+ async def play_turn(human_response, loc, player, cur, custom_token, request: gr.Request):
87
  """Executes a single turn of the game loop based on user input."""
88
  status = player.get_attribute()
89
  if not human_response.strip():
 
115
  }
116
  ]
117
  try:
118
+ response = await client.chat_completion(
119
  model=LLM_MODEL,
120
  messages=messages,
121
  max_tokens=500,
 
138
  attribute = player.get_attribute()
139
 
140
  # 3. Check for Game Over conditions
141
+ if attribute['hp'] <= 0:
142
  loc = -1
143
 
144
  cur = EVENTS[loc]
 
253
  user_input.submit(**turn_config)
254
 
255
  if __name__ == "__main__":
256
+ demo.queue(max_size=10).launch()