linoyts HF Staff commited on
Commit
617cd72
·
verified ·
1 Parent(s): 14a6f5e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -7
app.py CHANGED
@@ -171,7 +171,7 @@ Do NOT include JSON formatting or additional explanations.
171
  '''
172
 
173
  # --- Prompt Enhancement using Hugging Face InferenceClient ---
174
- def polish_prompt_hf(prompt, img_list):
175
  """
176
  Rewrites the prompt using a Hugging Face InferenceClient.
177
  """
@@ -179,13 +179,13 @@ def polish_prompt_hf(prompt, img_list):
179
  api_key = os.environ.get("HF_TOKEN")
180
  if not api_key:
181
  print("Warning: HF_TOKEN not set. Falling back to original prompt.")
182
- return prompt
183
 
184
  try:
185
  # Initialize the client
186
- prompt = f"{SYSTEM_PROMPT}\n\nUser Input: {prompt}\n\nRewritten Prompt:"
187
  client = InferenceClient(
188
- provider="cerebras",
189
  api_key=api_key,
190
  )
191
 
@@ -201,7 +201,7 @@ def polish_prompt_hf(prompt, img_list):
201
 
202
  # Call the API
203
  completion = client.chat.completions.create(
204
- model="Qwen/Qwen3-235B-A22B-Instruct-2507",
205
  messages=messages,
206
  )
207
 
@@ -209,7 +209,7 @@ def polish_prompt_hf(prompt, img_list):
209
  result = completion.choices[0].message.content
210
 
211
  # Try to extract JSON if present
212
- if '{"Rewritten"' in result:
213
  try:
214
  # Clean up the response
215
  result = result.replace('```json', '').replace('```', '')
@@ -226,7 +226,7 @@ def polish_prompt_hf(prompt, img_list):
226
  except Exception as e:
227
  print(f"Error during API call to Hugging Face: {e}")
228
  # Fallback to original prompt if enhancement fails
229
- return prompt
230
 
231
  def next_scene_prompt(original_prompt, img_list):
232
  """
 
171
  '''
172
 
173
  # --- Prompt Enhancement using Hugging Face InferenceClient ---
174
+ def polish_prompt_hf(original_prompt, img_list):
175
  """
176
  Rewrites the prompt using a Hugging Face InferenceClient.
177
  """
 
179
  api_key = os.environ.get("HF_TOKEN")
180
  if not api_key:
181
  print("Warning: HF_TOKEN not set. Falling back to original prompt.")
182
+ return original_prompt
183
 
184
  try:
185
  # Initialize the client
186
+ prompt = f"{SYSTEM_PROMPT}\n\nUser Input: {original_prompt}\n\nRewritten Prompt:"
187
  client = InferenceClient(
188
+ provider="nebius",
189
  api_key=api_key,
190
  )
191
 
 
201
 
202
  # Call the API
203
  completion = client.chat.completions.create(
204
+ model="Qwen/Qwen2.5-VL-72B-Instruct",
205
  messages=messages,
206
  )
207
 
 
209
  result = completion.choices[0].message.content
210
 
211
  # Try to extract JSON if present
212
+ if '"Rewritten"' in result:
213
  try:
214
  # Clean up the response
215
  result = result.replace('```json', '').replace('```', '')
 
226
  except Exception as e:
227
  print(f"Error during API call to Hugging Face: {e}")
228
  # Fallback to original prompt if enhancement fails
229
+ return original_prompt
230
 
231
  def next_scene_prompt(original_prompt, img_list):
232
  """