Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
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(
|
| 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
|
| 183 |
|
| 184 |
try:
|
| 185 |
# Initialize the client
|
| 186 |
-
prompt = f"{SYSTEM_PROMPT}\n\nUser Input: {
|
| 187 |
client = InferenceClient(
|
| 188 |
-
provider="
|
| 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/
|
| 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 '
|
| 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
|
| 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 |
"""
|