Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,22 +7,29 @@ import json
|
|
| 7 |
import uuid
|
| 8 |
import base64
|
| 9 |
|
| 10 |
-
# Initialize the Claude client
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
client = anthropic.Client(api_key=os.environ.get("ANTHROPIC_API_KEY"))
|
| 17 |
|
| 18 |
# Set page config
|
| 19 |
st.set_page_config(page_title="AI PowerPoint Creator", layout="wide")
|
| 20 |
|
| 21 |
-
#
|
| 22 |
-
try:
|
| 23 |
-
st.sidebar.write(f"Anthropic version: {anthropic.__version__}")
|
| 24 |
-
except:
|
| 25 |
-
st.sidebar.write("Couldn't determine Anthropic version")
|
| 26 |
|
| 27 |
# Initialize session state variables
|
| 28 |
if "current_stage" not in st.session_state:
|
|
@@ -72,8 +79,9 @@ def generate_storyboard(title, purpose, audience):
|
|
| 72 |
Start with an engaging title slide and end with a clear call-to-action or summary slide.
|
| 73 |
"""
|
| 74 |
|
| 75 |
-
|
| 76 |
-
|
|
|
|
| 77 |
response = client.messages.create(
|
| 78 |
model="claude-3-5-sonnet-20240620",
|
| 79 |
max_tokens=4000,
|
|
@@ -84,8 +92,8 @@ def generate_storyboard(title, purpose, audience):
|
|
| 84 |
]
|
| 85 |
)
|
| 86 |
response_text = response.content[0].text
|
| 87 |
-
|
| 88 |
-
#
|
| 89 |
response = client.completion(
|
| 90 |
prompt=f"{anthropic.HUMAN_PROMPT} {prompt} {anthropic.AI_PROMPT}",
|
| 91 |
model="claude-2.0",
|
|
@@ -130,8 +138,9 @@ def generate_slide_content(slide_info, template):
|
|
| 130 |
Focus on clarity, impact, and alignment with the slide's purpose.
|
| 131 |
"""
|
| 132 |
|
| 133 |
-
|
| 134 |
-
|
|
|
|
| 135 |
response = client.messages.create(
|
| 136 |
model="claude-3-5-sonnet-20240620",
|
| 137 |
max_tokens=2000,
|
|
@@ -142,8 +151,8 @@ def generate_slide_content(slide_info, template):
|
|
| 142 |
]
|
| 143 |
)
|
| 144 |
response_text = response.content[0].text
|
| 145 |
-
|
| 146 |
-
#
|
| 147 |
response = client.completion(
|
| 148 |
prompt=f"{anthropic.HUMAN_PROMPT} {prompt} {anthropic.AI_PROMPT}",
|
| 149 |
model="claude-2.0",
|
|
@@ -250,7 +259,7 @@ def render_ideation_stage():
|
|
| 250 |
if storyboard:
|
| 251 |
st.session_state.storyboard = storyboard
|
| 252 |
st.session_state.current_stage = "storyboard"
|
| 253 |
-
st.
|
| 254 |
|
| 255 |
def render_storyboard_stage():
|
| 256 |
st.header("Step 2: Review and Edit Storyboard")
|
|
@@ -296,11 +305,11 @@ def render_storyboard_stage():
|
|
| 296 |
with col1:
|
| 297 |
if st.button("⬅️ Back to Ideation"):
|
| 298 |
st.session_state.current_stage = "ideation"
|
| 299 |
-
st.
|
| 300 |
with col2:
|
| 301 |
if st.button("Continue to Template Selection ➡️"):
|
| 302 |
st.session_state.current_stage = "template"
|
| 303 |
-
st.
|
| 304 |
|
| 305 |
def render_template_stage():
|
| 306 |
st.header("Step 3: Select a Template")
|
|
@@ -328,7 +337,7 @@ def render_template_stage():
|
|
| 328 |
with col1:
|
| 329 |
if st.button("⬅️ Back to Storyboard"):
|
| 330 |
st.session_state.current_stage = "storyboard"
|
| 331 |
-
st.
|
| 332 |
with col2:
|
| 333 |
if st.button("Generate Slides ➡️"):
|
| 334 |
st.session_state.current_stage = "slides"
|
|
@@ -341,7 +350,7 @@ def render_template_stage():
|
|
| 341 |
slides_content.append(slide_content)
|
| 342 |
|
| 343 |
st.session_state.slides_content = slides_content
|
| 344 |
-
st.
|
| 345 |
|
| 346 |
def render_slides_stage():
|
| 347 |
st.header("Step 4: Review and Edit Slides")
|
|
@@ -350,7 +359,7 @@ def render_slides_stage():
|
|
| 350 |
st.warning("No slides content available. Please go back and generate slides.")
|
| 351 |
if st.button("⬅️ Back to Template Selection"):
|
| 352 |
st.session_state.current_stage = "template"
|
| 353 |
-
st.
|
| 354 |
return
|
| 355 |
|
| 356 |
# Display slides for review with edit options
|
|
@@ -391,11 +400,11 @@ def render_slides_stage():
|
|
| 391 |
with col1:
|
| 392 |
if st.button("⬅️ Back to Template Selection"):
|
| 393 |
st.session_state.current_stage = "template"
|
| 394 |
-
st.
|
| 395 |
with col2:
|
| 396 |
if st.button("Create PowerPoint ➡️"):
|
| 397 |
st.session_state.current_stage = "export"
|
| 398 |
-
st.
|
| 399 |
|
| 400 |
def render_export_stage():
|
| 401 |
st.header("Step 5: Export Presentation")
|
|
|
|
| 7 |
import uuid
|
| 8 |
import base64
|
| 9 |
|
| 10 |
+
# Initialize the Claude client - handle different package versions
|
| 11 |
+
try:
|
| 12 |
+
# Get the version
|
| 13 |
+
import pkg_resources
|
| 14 |
+
anthropic_version = pkg_resources.get_distribution("anthropic").version
|
| 15 |
+
st.sidebar.write(f"Detected Anthropic version: {anthropic_version}")
|
| 16 |
+
|
| 17 |
+
# Initialize based on version
|
| 18 |
+
if anthropic_version.startswith(("0.3", "0.4", "0.5")):
|
| 19 |
+
# Older API
|
| 20 |
+
client = anthropic.Client(api_key=os.environ.get("ANTHROPIC_API_KEY"))
|
| 21 |
+
else:
|
| 22 |
+
# Newer API
|
| 23 |
+
client = anthropic.Anthropic(api_key=os.environ.get("ANTHROPIC_API_KEY"))
|
| 24 |
+
except Exception as e:
|
| 25 |
+
st.sidebar.write(f"Error detecting Anthropic version: {e}")
|
| 26 |
+
# Default to older API which is more likely to be compatible
|
| 27 |
client = anthropic.Client(api_key=os.environ.get("ANTHROPIC_API_KEY"))
|
| 28 |
|
| 29 |
# Set page config
|
| 30 |
st.set_page_config(page_title="AI PowerPoint Creator", layout="wide")
|
| 31 |
|
| 32 |
+
# Anthropic version is now checked during client initialization
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
# Initialize session state variables
|
| 35 |
if "current_stage" not in st.session_state:
|
|
|
|
| 79 |
Start with an engaging title slide and end with a clear call-to-action or summary slide.
|
| 80 |
"""
|
| 81 |
|
| 82 |
+
# Check which client type we have
|
| 83 |
+
if hasattr(client, "messages"):
|
| 84 |
+
# Newer API
|
| 85 |
response = client.messages.create(
|
| 86 |
model="claude-3-5-sonnet-20240620",
|
| 87 |
max_tokens=4000,
|
|
|
|
| 92 |
]
|
| 93 |
)
|
| 94 |
response_text = response.content[0].text
|
| 95 |
+
else:
|
| 96 |
+
# Older API
|
| 97 |
response = client.completion(
|
| 98 |
prompt=f"{anthropic.HUMAN_PROMPT} {prompt} {anthropic.AI_PROMPT}",
|
| 99 |
model="claude-2.0",
|
|
|
|
| 138 |
Focus on clarity, impact, and alignment with the slide's purpose.
|
| 139 |
"""
|
| 140 |
|
| 141 |
+
# Check which client type we have
|
| 142 |
+
if hasattr(client, "messages"):
|
| 143 |
+
# Newer API
|
| 144 |
response = client.messages.create(
|
| 145 |
model="claude-3-5-sonnet-20240620",
|
| 146 |
max_tokens=2000,
|
|
|
|
| 151 |
]
|
| 152 |
)
|
| 153 |
response_text = response.content[0].text
|
| 154 |
+
else:
|
| 155 |
+
# Older API
|
| 156 |
response = client.completion(
|
| 157 |
prompt=f"{anthropic.HUMAN_PROMPT} {prompt} {anthropic.AI_PROMPT}",
|
| 158 |
model="claude-2.0",
|
|
|
|
| 259 |
if storyboard:
|
| 260 |
st.session_state.storyboard = storyboard
|
| 261 |
st.session_state.current_stage = "storyboard"
|
| 262 |
+
st.rerun()
|
| 263 |
|
| 264 |
def render_storyboard_stage():
|
| 265 |
st.header("Step 2: Review and Edit Storyboard")
|
|
|
|
| 305 |
with col1:
|
| 306 |
if st.button("⬅️ Back to Ideation"):
|
| 307 |
st.session_state.current_stage = "ideation"
|
| 308 |
+
st.rerun()
|
| 309 |
with col2:
|
| 310 |
if st.button("Continue to Template Selection ➡️"):
|
| 311 |
st.session_state.current_stage = "template"
|
| 312 |
+
st.rerun()
|
| 313 |
|
| 314 |
def render_template_stage():
|
| 315 |
st.header("Step 3: Select a Template")
|
|
|
|
| 337 |
with col1:
|
| 338 |
if st.button("⬅️ Back to Storyboard"):
|
| 339 |
st.session_state.current_stage = "storyboard"
|
| 340 |
+
st.rerun()
|
| 341 |
with col2:
|
| 342 |
if st.button("Generate Slides ➡️"):
|
| 343 |
st.session_state.current_stage = "slides"
|
|
|
|
| 350 |
slides_content.append(slide_content)
|
| 351 |
|
| 352 |
st.session_state.slides_content = slides_content
|
| 353 |
+
st.rerun()
|
| 354 |
|
| 355 |
def render_slides_stage():
|
| 356 |
st.header("Step 4: Review and Edit Slides")
|
|
|
|
| 359 |
st.warning("No slides content available. Please go back and generate slides.")
|
| 360 |
if st.button("⬅️ Back to Template Selection"):
|
| 361 |
st.session_state.current_stage = "template"
|
| 362 |
+
st.rerun()
|
| 363 |
return
|
| 364 |
|
| 365 |
# Display slides for review with edit options
|
|
|
|
| 400 |
with col1:
|
| 401 |
if st.button("⬅️ Back to Template Selection"):
|
| 402 |
st.session_state.current_stage = "template"
|
| 403 |
+
st.rerun()
|
| 404 |
with col2:
|
| 405 |
if st.button("Create PowerPoint ➡️"):
|
| 406 |
st.session_state.current_stage = "export"
|
| 407 |
+
st.rerun()
|
| 408 |
|
| 409 |
def render_export_stage():
|
| 410 |
st.header("Step 5: Export Presentation")
|