Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,6 +10,11 @@ import base64
|
|
| 10 |
# Initialize the Claude client
|
| 11 |
client = anthropic.Anthropic(api_key=os.environ.get("ANTHROPIC_API_KEY"))
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
# Set page config
|
| 14 |
st.set_page_config(page_title="AI PowerPoint Creator", layout="wide")
|
| 15 |
|
|
@@ -61,18 +66,29 @@ def generate_storyboard(title, purpose, audience):
|
|
| 61 |
Start with an engaging title slide and end with a clear call-to-action or summary slide.
|
| 62 |
"""
|
| 63 |
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
-
# Extract the JSON from the response
|
| 75 |
-
response_text = response.content[0].text
|
| 76 |
try:
|
| 77 |
# Find JSON in the response
|
| 78 |
json_start = response_text.find("[")
|
|
@@ -108,8 +124,7 @@ def generate_slide_content(slide_info, template):
|
|
| 108 |
Focus on clarity, impact, and alignment with the slide's purpose.
|
| 109 |
"""
|
| 110 |
|
| 111 |
-
|
| 112 |
-
model="claude-3-5-sonnet-20240620",
|
| 113 |
max_tokens=2000,
|
| 114 |
temperature=0.5,
|
| 115 |
system="You are an expert presentation content creator. Always output valid JSON.",
|
|
|
|
| 10 |
# Initialize the Claude client
|
| 11 |
client = anthropic.Anthropic(api_key=os.environ.get("ANTHROPIC_API_KEY"))
|
| 12 |
|
| 13 |
+
# Fallback for older versions of the Anthropic library
|
| 14 |
+
if not hasattr(client, "messages"):
|
| 15 |
+
# For older versions of the anthropic package
|
| 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 |
|
|
|
|
| 66 |
Start with an engaging title slide and end with a clear call-to-action or summary slide.
|
| 67 |
"""
|
| 68 |
|
| 69 |
+
try:
|
| 70 |
+
# Try newer Anthropic API format first
|
| 71 |
+
response = client.messages.create(
|
| 72 |
+
model="claude-3-5-sonnet-20240620",
|
| 73 |
+
max_tokens=4000,
|
| 74 |
+
temperature=0.7,
|
| 75 |
+
system="You are an expert presentation designer specializing in creating logical, compelling PowerPoint storyboards. Always output valid JSON.",
|
| 76 |
+
messages=[
|
| 77 |
+
{"role": "user", "content": prompt}
|
| 78 |
+
]
|
| 79 |
+
)
|
| 80 |
+
response_text = response.content[0].text
|
| 81 |
+
except (AttributeError, TypeError):
|
| 82 |
+
# Fallback for older Anthropic API
|
| 83 |
+
response = client.completion(
|
| 84 |
+
prompt=f"{anthropic.HUMAN_PROMPT} {prompt} {anthropic.AI_PROMPT}",
|
| 85 |
+
model="claude-2.0",
|
| 86 |
+
max_tokens_to_sample=4000,
|
| 87 |
+
temperature=0.7
|
| 88 |
+
)
|
| 89 |
+
response_text = response.completion
|
| 90 |
|
| 91 |
+
# Extract the JSON from the response - this is now handled in the try/except block above
|
|
|
|
| 92 |
try:
|
| 93 |
# Find JSON in the response
|
| 94 |
json_start = response_text.find("[")
|
|
|
|
| 124 |
Focus on clarity, impact, and alignment with the slide's purpose.
|
| 125 |
"""
|
| 126 |
|
| 127 |
+
|
|
|
|
| 128 |
max_tokens=2000,
|
| 129 |
temperature=0.5,
|
| 130 |
system="You are an expert presentation content creator. Always output valid JSON.",
|