Spaces:
Paused
Paused
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -143,6 +143,8 @@ def create_presentation(
|
|
| 143 |
|
| 144 |
logs = [f"Model: {MODEL_ID}", f"Topic: {topic}"]
|
| 145 |
max_turns = 30
|
|
|
|
|
|
|
| 146 |
|
| 147 |
for turn_idx in range(max_turns):
|
| 148 |
progress(0.1 + (0.8 * turn_idx / max_turns), desc=f"Turn {turn_idx + 1}...")
|
|
@@ -167,6 +169,28 @@ def create_presentation(
|
|
| 167 |
tool_name = tool_call.get("tool", "")
|
| 168 |
logs.append(f"Turn {turn_idx}: {tool_name}")
|
| 169 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
# Execute action
|
| 171 |
try:
|
| 172 |
action = SlideForgeAction(tool=tool_name, parameters=params)
|
|
|
|
| 143 |
|
| 144 |
logs = [f"Model: {MODEL_ID}", f"Topic: {topic}"]
|
| 145 |
max_turns = 30
|
| 146 |
+
last_tool = None
|
| 147 |
+
repeat_count = 0
|
| 148 |
|
| 149 |
for turn_idx in range(max_turns):
|
| 150 |
progress(0.1 + (0.8 * turn_idx / max_turns), desc=f"Turn {turn_idx + 1}...")
|
|
|
|
| 169 |
tool_name = tool_call.get("tool", "")
|
| 170 |
logs.append(f"Turn {turn_idx}: {tool_name}")
|
| 171 |
|
| 172 |
+
# Detect repetitive loops
|
| 173 |
+
if tool_name == last_tool:
|
| 174 |
+
repeat_count += 1
|
| 175 |
+
if repeat_count >= 3:
|
| 176 |
+
logs.append(f" Breaking loop - {tool_name} repeated {repeat_count} times")
|
| 177 |
+
# Force next logical action
|
| 178 |
+
if not env.state.outline:
|
| 179 |
+
tool_name = "create_outline"
|
| 180 |
+
params = {"sections": [{"title": f"Slide {i+1}: {topic}", "bullet_points": [f"Point {j+1}" for j in range(sections_per_slide)]} for i in range(num_slides)]}
|
| 181 |
+
elif sum(1 for h in env.state.slides_html if h) < num_slides:
|
| 182 |
+
idx = sum(1 for h in env.state.slides_html if h)
|
| 183 |
+
entry = env.state.outline[idx] if idx < len(env.state.outline) else {"title": f"Slide {idx+1}"}
|
| 184 |
+
tool_name = "generate_slide"
|
| 185 |
+
params = {"slide_idx": idx, "title": entry.get("title", f"Slide {idx+1}"), "sections": [{"heading": bp, "body": f"Details about {bp}"} for bp in entry.get("bullet_points", [f"Point {j+1}" for j in range(sections_per_slide)])[:sections_per_slide]]}
|
| 186 |
+
else:
|
| 187 |
+
tool_name = "finalize"
|
| 188 |
+
params = {}
|
| 189 |
+
repeat_count = 0
|
| 190 |
+
else:
|
| 191 |
+
repeat_count = 0
|
| 192 |
+
last_tool = tool_name
|
| 193 |
+
|
| 194 |
# Execute action
|
| 195 |
try:
|
| 196 |
action = SlideForgeAction(tool=tool_name, parameters=params)
|