diff --git a/docs/docs.json b/docs/docs.json index 459793c4..eadbefcf 100644 --- a/docs/docs.json +++ b/docs/docs.json @@ -33,7 +33,8 @@ { "group": "Tutorials", "pages": [ - "tutorial/generate-presentation-over-api" + "tutorial/generate-presentation-over-api", + "tutorial/generate-presentation-from-csv" ] } ] @@ -76,4 +77,4 @@ "github": "https://github.com/presenton/presenton" } } -} +} \ No newline at end of file diff --git a/docs/tutorial/generate-presentation-from-csv.mdx.mdx b/docs/tutorial/generate-presentation-from-csv.mdx.mdx new file mode 100644 index 00000000..20a0ea0c --- /dev/null +++ b/docs/tutorial/generate-presentation-from-csv.mdx.mdx @@ -0,0 +1,150 @@ +--- +title: "Create Presentations from CSV using AI" +description: "Step-by-step guide to generating presentations from a CSV file" +--- + +In this tutorial, we will generate personalized student report presentations using self hosted Presenton's API and a Python script. + +This tutorial extends [Generate a PPT via API in 5 Minutes](./generate-presentation-over-api) and shows you how to automate the creation of personalized student report presentations from a CSV file using Python. + +So, do check it before continuing with this and make sure you have Presenton running locally or any server and you are able to generate presentations with it. + +--- + +## 1. Prepare Your CSV File + +Save your student data as `students.csv`: + +```csv +Name,Final Grade,ECA Participation,Sports Involvement,Quiz Scores,Class Behavior,Comment +Anaya Sharma,88,High,Moderate,92,Excellent,"Balanced performer with high curiosity" +Rohan Mehta,73,Low,None,75,Good,"Needs motivation beyond academics" +Meera Kapoor,94,Moderate,High,96,Excellent,"Academic excellence and team spirit" +Aarav Patel,62,None,None,58,Average,"Struggling across areas, needs focused help" +``` + +--- + +## 2. Install Python Requirements + +You’ll need the `requests` and `pandas` libraries: + +```bash +pip install requests pandas +``` + +--- + +## 3. Write the Python Script + +Let’s build the script step by step. + +### a. Import Libraries + +```python +import os +import pandas as pd +import requests +``` + +### b. Creat presentations directory + +```python +os.makedirs('presentations', exist_ok=True) +``` + +### c. Load the CSV + +```python +df = pd.read_csv("students.csv") +``` + +### d. Define a Function to Build the Prompt + +```python +def build_prompt(row): + return ( + f"Student Name: {row['Name']}\n" + f"Final Grade: {row['Final Grade']}\n" + f"ECA Participation: {row['ECA Participation']}\n" + f"Sports Involvement: {row['Sports Involvement']}\n" + f"Quiz Scores: {row['Quiz Scores']}\n" + f"Class Behavior: {row['Class Behavior']}\n" + f"Teacher's Comment: {row['Comment']}\n\n" + "Generate a parent-friendly presentation summarizing this student's academic and extracurricular performance, " + "highlighting strengths, areas for improvement, and any special notes from the teacher." + ) +``` + +### e. Loop Over Each Student and Generate a Presentation + +```python +for idx, row in df.iterrows(): + print(f"Generating presentation for {row['Name']}") + prompt = build_prompt(row) + data = { + "prompt": prompt, + "n_slides": "8", + "language": "English", + "theme": "light", + "export_as": "pdf" + } + response = requests.post( + "http://localhost:5000/api/v1/ppt/generate/presentation", + data=data + ) + if response.ok: + result = response.json() + print("Downloading presentation...") + # Prepend the host to the path + download_url = f"http://localhost:5000{result['path']}" + filename = f"presentations/{result['path'].split('/')[-1]}" + # Download and save the file + file_response = requests.get(download_url) + if file_response.ok: + with open(filename, 'wb') as f: + f.write(file_response.content) + print(f"Presentation for {row['Name']} saved as {filename}") + else: + print(f"Failed to download presentation for {row['Name']}: {file_response.status_code}") + else: + print(f"Failed to generate presentation for {row['Name']}: {response.text}") +``` + +Generated presentations will be saved in `presentations` directory. + +You may change the URL `http://localhost:5000` to the URL of your Presenton instance. + +--- + +## 4. Run the Script + +Save your script as `generate_reports.py` and run: + +```bash +python generate_reports.py +``` + +Each student will get a personalized presentation, and you’ll see the download path for each file in your terminal. + +--- + +## 5. How It Works + +- The script reads each row from your CSV. +- It builds a detailed prompt for Presenton’s API (see [API Reference](./mdx.docs)). +- It sends a POST request to generate a presentation for each student. +- The API returns a download path for each generated PPTX. +- The presentation file is downloaded and saved in `presentations` folder. + +--- + +## 6. Next Steps + +- You can customize the prompt or number of slides as needed. +- For more on API options, see [Generate a PPT via API in 5 Minutes](./generate-ppt-via-api). +- For advanced configuration (e.g., using Ollama or GPU), see [Environment Variables](./configurations/environment-variables), [Using GPU](./configurations/using-gpu), and [Using Ollama Models](./configurations/using-ollama-models). + + + Need help? See the [full documentation](./index) or open an issue on GitHub. + \ No newline at end of file diff --git a/docs/tutorial/generate-presentation-over-api.mdx b/docs/tutorial/generate-presentation-over-api.mdx index c2e0a4aa..46190286 100644 --- a/docs/tutorial/generate-presentation-over-api.mdx +++ b/docs/tutorial/generate-presentation-over-api.mdx @@ -1,5 +1,5 @@ --- -title: "Generate PPT via API in 5 minutes" +title: "Generate Presentations via API in 5 minutes" description: "Steps to generate professional AI presentations via self hosted Presenton's API in just 5 minutes. " --- @@ -23,7 +23,7 @@ You're now ready to run Presenton's docker image to start generating presentatio We will go with `GOOGLE` in this guide as it's relatively simpler to configure and free to start with. You will have to grab its API Key from [Google AI Studio](https://aistudio.google.com/apikey). -You can find details to run with other providers in [Environment Variables](./configurations/environment-variables). +You can find details to run with other providers in [Environment Variables](./environment-variables). Now, open your command line and execute the relevant command based on your OS: @@ -133,12 +133,12 @@ Here's a quick reference for the key parameters you can set: | Parameter | Type | Required | Description | | ----------- | ------ | -------- | ---------------------------------------------------------- | -| `prompt` | string | Yes | Topic/title of your presentation | -| `n_slides` | int | No | Number of slides (default: 8; min: 5, max: 15) | -| `language` | string | No | Language you'd like the presentation in (default: English) | -| `theme` | string | No | Optional styling (e.g.: "light", "dark", "royal_blue") | -| `documents` | file[] | No | Additional supporting documents (PDF/PPTX/DOCX/TXT) | -| `export_as` | string | No | "pptx" or "pdf" (default: pptx) | +| `prompt` | string | 👍 Yes | Topic/title of your presentation | +| `n_slides` | int | ❌ No | Number of slides (default: 8; min: 5, max: 15) | +| `language` | string | ❌ No | Language you'd like the presentation in (default: English) | +| `theme` | string | ❌ No | Optional styling (e.g.: "light", "dark", "royal_blue") | +| `documents` | file[] | ❌ No | Additional supporting documents (PDF/PPTX/DOCX/TXT) | +| `export_as` | string | ❌ No | "pptx" or "pdf" (default: pptx) | Yes, it can generate presentations directly from most popular file formats. Make sure you understand the context window of model you're using with respect to file size. @@ -164,7 +164,6 @@ Here's what a normal, successful response looks like: > Note: Make sure to prepend your server's root URL to the path and edit_path fields in the response to construct valid links. -It might take a minutes to generate presentation as per the number of slides and choosen LLM Provider. --- ## Step 8: Built-in Presentation Themes @@ -193,4 +192,4 @@ Once you're comfortable and ready for more: **That's it\!** You've successfully generated a professional-looking presentation through an easy-to-use API endpoint. -If you have more questions or want to explore further, the [complete documentation](./index) is always here to help you. +If you have more questions or want to explore further, the [complete documentation](./index) is always here to help you. \ No newline at end of file