ppt-generator / app.py
swcrazyfan's picture
Update app.py
954adda
import gradio as gr
import openai
import os
openai.api_key = os.environ["OPENAI_API_KEY"]
def generate_pptx(lesson_topic):
prompt = (
"Create PowerPoint slides for a lesson plan. The slides should be visually engaging, include concise headings and bullet points, and have relevant images or icons when necessary. Limit each slide to a maximum of 4 sub-points and a single image or icon when relevant. Divide the same heading into multiple slides if required to make the points more clear."
"\n\nFor the first slide, include the lesson title and relevant sub-points. Also, include a closing slide with takeaways from the lesson. Choose a PowerPoint theme from these options: dark, light, corporate, or playful, depending on the lesson's context."
"\n\nThe output should be suitable for use with the python-pptx library to create a PowerPoint presentation."
"\n\nLesson Plan:\n{lesson_topic}"
"\n\nFor each slide, provide this information:\n\n"
"#. Slide (slide_title):\n"
"Heading: concise_heading\n"
"Sub-point 1:\n"
"Sub-point 2:\n"
"...\n"
"If an image is relevant, include: 'Image: short_description_of_image'\n"
"If an icon is relevant, include: 'Icon: font_awesome_icon_code'\n"
"When creating the slides, remember to use clear and concise language, write the slides for the students to understand, and use appropriate images or icons, and choose a suitable theme for the PowerPoint presentation."
.format(lesson_topic=lesson_topic)
)
response = openai.ChatCompletion.create(
model="gpt-4",
messages=[
{
"role": "system",
"content": (
"You are a helpful assistant capable of creating clear and concise PowerPoint slide outlines used by teachers during their lessons based on a given lesson plan."
),
},
{"role": "user", "content": prompt},
],
max_tokens=1000,
n=1,
stop=None,
temperature=0.7,
# top_p=0.9,
)
output = response.choices[0]['message']['content']
return output
inputs = gr.inputs.Textbox(label="Lesson topic")
outputs = gr.outputs.Textbox(label="Generated text")
gr.Interface(fn=generate_pptx, inputs=inputs, outputs=outputs).launch()