Spaces:
Running
Running
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +52 -10
src/streamlit_app.py
CHANGED
@@ -23,6 +23,10 @@ if 'presentation_title' not in st.session_state:
|
|
23 |
st.session_state.presentation_title = ""
|
24 |
if 'openai_api_key' not in st.session_state:
|
25 |
st.session_state.openai_api_key = ""
|
|
|
|
|
|
|
|
|
26 |
if 'css_style' not in st.session_state:
|
27 |
st.session_state.css_style = """
|
28 |
body {
|
@@ -81,11 +85,35 @@ if 'css_style' not in st.session_state:
|
|
81 |
# Function to create presentation plan using LLM as "Planning Agent"
|
82 |
def create_presentation_plan(topic, num_slides, key_points):
|
83 |
try:
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
|
90 |
slides = []
|
91 |
# Always create a title slide
|
@@ -399,11 +427,25 @@ with tabs[3]:
|
|
399 |
st.markdown(get_slide_download_link(), unsafe_allow_html=True)
|
400 |
st.info("This will download a ZIP file containing all your slides as HTML files with consistent styling. You can open each slide in a browser or use them in your presentation software.")
|
401 |
|
402 |
-
# Sidebar with instructions
|
403 |
-
st.sidebar.title("
|
404 |
-
|
405 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
406 |
|
|
|
|
|
|
|
407 |
This app uses a multi-agent approach to create presentations:
|
408 |
|
409 |
1. **Planning Agent**: Develops the structure and content flow of your presentation
|
@@ -424,4 +466,4 @@ This app uses a multi-agent approach to create presentations:
|
|
424 |
""")
|
425 |
|
426 |
st.sidebar.markdown("---")
|
427 |
-
st.sidebar.info("
|
|
|
23 |
st.session_state.presentation_title = ""
|
24 |
if 'openai_api_key' not in st.session_state:
|
25 |
st.session_state.openai_api_key = ""
|
26 |
+
if 'style_instructions' not in st.session_state:
|
27 |
+
st.session_state.style_instructions = ""
|
28 |
+
if 'content_instructions' not in st.session_state:
|
29 |
+
st.session_state.content_instructions = ""
|
30 |
if 'css_style' not in st.session_state:
|
31 |
st.session_state.css_style = """
|
32 |
body {
|
|
|
85 |
# Function to create presentation plan using LLM as "Planning Agent"
|
86 |
def create_presentation_plan(topic, num_slides, key_points):
|
87 |
try:
|
88 |
+
if st.session_state.openai_api_key:
|
89 |
+
# Use actual OpenAI API
|
90 |
+
client = openai.OpenAI(api_key=st.session_state.openai_api_key)
|
91 |
+
response = client.chat.completions.create(
|
92 |
+
model="gpt-3.5-turbo", # You can change to gpt-4 if available
|
93 |
+
messages=[
|
94 |
+
{"role": "system", "content": "You are a presentation planning expert. Create a detailed presentation outline."},
|
95 |
+
{"role": "user", "content": f"Create a presentation plan on '{topic}' with {num_slides} slides. Key points to include: {key_points}. Return your response as a JSON object with this structure: {{\"title\": \"Presentation Title\", \"num_slides\": number, \"slides\": [{{\"slide_number\": 1, \"title\": \"Slide Title\", \"type\": \"title_slide\", \"content\": \"Content description\"}}]}}"}
|
96 |
+
],
|
97 |
+
response_format={"type": "json_object"}
|
98 |
+
)
|
99 |
+
# Parse the JSON response
|
100 |
+
try:
|
101 |
+
return json.loads(response.choices[0].message.content)
|
102 |
+
except json.JSONDecodeError:
|
103 |
+
# Fallback to simulated response if JSON parsing fails
|
104 |
+
st.warning("Could not parse LLM response as JSON. Using simulated plan instead.")
|
105 |
+
return simulate_presentation_plan(topic, num_slides, key_points)
|
106 |
+
else:
|
107 |
+
# Fallback to simulated response
|
108 |
+
return simulate_presentation_plan(topic, num_slides, key_points)
|
109 |
+
except Exception as e:
|
110 |
+
st.error(f"Error creating presentation plan: {str(e)}")
|
111 |
+
# Fallback to simulated response
|
112 |
+
return simulate_presentation_plan(topic, num_slides, key_points)
|
113 |
+
|
114 |
+
def simulate_presentation_plan(topic, num_slides, key_points):
|
115 |
+
# Simulate an LLM response with a predefined structure
|
116 |
+
time.sleep(1) # Simulate API call time
|
117 |
|
118 |
slides = []
|
119 |
# Always create a title slide
|
|
|
427 |
st.markdown(get_slide_download_link(), unsafe_allow_html=True)
|
428 |
st.info("This will download a ZIP file containing all your slides as HTML files with consistent styling. You can open each slide in a browser or use them in your presentation software.")
|
429 |
|
430 |
+
# Sidebar with instructions and settings
|
431 |
+
st.sidebar.title("AI PowerPoint Maker")
|
432 |
+
|
433 |
+
# OpenAI API Key input
|
434 |
+
st.sidebar.subheader("OpenAI API Settings")
|
435 |
+
api_key = st.sidebar.text_input("Enter your OpenAI API Key",
|
436 |
+
value=st.session_state.openai_api_key,
|
437 |
+
type="password",
|
438 |
+
help="Your API key will be used to generate better presentation content and slides.")
|
439 |
+
|
440 |
+
if api_key:
|
441 |
+
st.session_state.openai_api_key = api_key
|
442 |
+
st.sidebar.success("✅ API Key set successfully!")
|
443 |
+
else:
|
444 |
+
st.sidebar.info("ℹ️ No API Key provided. The app will use simulated responses.")
|
445 |
|
446 |
+
st.sidebar.markdown("---")
|
447 |
+
st.sidebar.subheader("How It Works")
|
448 |
+
st.sidebar.markdown("""
|
449 |
This app uses a multi-agent approach to create presentations:
|
450 |
|
451 |
1. **Planning Agent**: Develops the structure and content flow of your presentation
|
|
|
466 |
""")
|
467 |
|
468 |
st.sidebar.markdown("---")
|
469 |
+
st.sidebar.info("When the OpenAI API key is provided, this app will use the actual OpenAI API for both the planning and HTML creation steps. Without an API key, it will use simulated responses for demonstration purposes.")
|