sqfoo commited on
Commit
c66bc88
·
verified ·
1 Parent(s): caf9555

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -11
app.py CHANGED
@@ -16,12 +16,14 @@ from moviepy.video.io.ImageSequenceClip import ImageSequenceClip
16
  from settings import EVENTS
17
  from player import Player
18
  from utils import PROMPT, INPUT_PROMPT, extract_after_final_answer
 
19
 
20
  # Initialize the HF Inference Client
21
  # It will automatically pick up the HF_TOKEN environment variable if it's set
22
 
23
  # Define the models we want to use from the Hugging Face Hub
24
  LLM_MODEL = "Qwen/Qwen2.5-7B-Instruct"
 
25
 
26
  target_size=(1024, 1024)
27
 
@@ -113,22 +115,26 @@ def play_turn(human_response, loc, player, cur, custom_token, request: gr.Reques
113
  return
114
 
115
  # 1. Process AI Model Response
 
116
  messages = [
117
  {
118
  "role": "user",
119
- "content": PROMPT + INPUT_PROMPT.format(human_response)
120
  }
121
  ]
 
122
  try:
123
- client = InferenceClient(
124
- api_key=chosen_token
125
- )
126
- response = client.chat_completion(
127
- model=LLM_MODEL,
128
- messages=messages,
129
- max_tokens=500,
130
- temperature=0.7
131
- )
 
 
132
  except Exception as e:
133
  yield (
134
  f"Error calling API: {str(e)}",
@@ -139,7 +145,9 @@ def play_turn(human_response, loc, player, cur, custom_token, request: gr.Reques
139
  )
140
  return
141
 
142
- processed_response = extract_after_final_answer(response.choices[0].message.content)
 
 
143
  print(processed_response)
144
  # 2. Update Game State / Location
145
  loc = cur._next(processed_response, player)
 
16
  from settings import EVENTS
17
  from player import Player
18
  from utils import PROMPT, INPUT_PROMPT, extract_after_final_answer
19
+ from llm import *
20
 
21
  # Initialize the HF Inference Client
22
  # It will automatically pick up the HF_TOKEN environment variable if it's set
23
 
24
  # Define the models we want to use from the Hugging Face Hub
25
  LLM_MODEL = "Qwen/Qwen2.5-7B-Instruct"
26
+ MODEL_CONFIG = HUGGINGFACE_LITE
27
 
28
  target_size=(1024, 1024)
29
 
 
115
  return
116
 
117
  # 1. Process AI Model Response
118
+ full_msg = PROMPT + INPUT_PROMPT.format(human_response)
119
  messages = [
120
  {
121
  "role": "user",
122
+ "content": full_msg
123
  }
124
  ]
125
+
126
  try:
127
+ model = setup_model(MODEL_CONFIG)
128
+ response = model.invoke(full_msg)
129
+ # client = InferenceClient(
130
+ # api_key=chosen_token
131
+ # )
132
+ # response = client.chat_completion(
133
+ # model=LLM_MODEL,
134
+ # messages=messages,
135
+ # max_tokens=500,
136
+ # temperature=0.7
137
+ # )
138
  except Exception as e:
139
  yield (
140
  f"Error calling API: {str(e)}",
 
145
  )
146
  return
147
 
148
+ # processed_response = extract_after_final_answer(response.choices[0].message.content)
149
+ processed_response = extract_after_final_answer(response.content)
150
+
151
  print(processed_response)
152
  # 2. Update Game State / Location
153
  loc = cur._next(processed_response, player)