diff --git a/week4/community-contributions/emmy/README.md b/week4/community-contributions/emmy/README.md new file mode 100644 index 0000000..61a1aae --- /dev/null +++ b/week4/community-contributions/emmy/README.md @@ -0,0 +1,41 @@ +# PrettyPage Generator + +Transform any text into a beautiful, responsive webpage. + +## What it does + +Paste your text (notes, articles, documentation, etc.) and get a styled, single-page website using your exact words. Choose from different themes like Minimal, Professional, Colorful, or Modern Gradient. + +## Requirements + +- Python 3.8+ +- OpenAI API key +- Google API key (optional, for Gemini) + +## Setup + +1. Install dependencies: +```bash +pip install gradio openai python-dotenv +``` + +2. Create a `.env` file: +``` +OPENAI_API_KEY=your_openai_key_here +GOOGLE_API_KEY=your_google_key_here +``` + +3. Run the app: +```bash +python text_to_html.py +``` + +4. Open the link in your browser + +## Usage + +1. Paste your text in the input box +2. Choose a model (GPT-4o-mini or Gemini-Flash) +3. Select a style theme +4. Click "Generate Page" +5. Copy the HTML and save as `index.html` \ No newline at end of file diff --git a/week4/community-contributions/emmy/text_to_html.py b/week4/community-contributions/emmy/text_to_html.py new file mode 100644 index 0000000..a9ef113 --- /dev/null +++ b/week4/community-contributions/emmy/text_to_html.py @@ -0,0 +1,222 @@ +import os +from dotenv import load_dotenv +from openai import OpenAI +import gradio as gr + +# --- Load environment keys --- +load_dotenv(override=True) +openai_api_key = os.getenv("OPENAI_API_KEY") +google_api_key = os.getenv("GOOGLE_API_KEY") + +# --- Model config --- +MODEL_MAP = { + "GPT-4o-mini": { + "model": "gpt-4o-mini", + "key": openai_api_key, + "endpoint": "https://api.openai.com/v1" + }, + "Gemini-Flash": { + "model": "gemini-2.5-flash", + "key": google_api_key, + "endpoint": "https://generativelanguage.googleapis.com/v1beta/openai/" + } +} + +class PageBuilder: + def __init__(self, model_choice="GPT-4o-mini"): + self.set_model(model_choice) + + def set_model(self, model_choice: str): + spec = MODEL_MAP[model_choice] + self.client = OpenAI( + api_key=spec["key"], + base_url=spec["endpoint"] + ) + self.model_name = spec["model"] + + def build_page(self, raw_text: str, theme: str) -> str: + """ + Ask the model for a self-contained HTML page (HTML + + """ + return html_page.replace("", fix + "\n") if "" in html_page else fix + html_page + +def build_interface(): + with gr.Blocks( + title="PrettyPage", + theme=gr.themes.Soft(primary_hue="indigo", neutral_hue="slate") + ) as demo: + gr.Markdown( + """ +
+ Paste any text. Get a clean, beautiful, responsive webpage using your exact words. +
+index.html and open it in your browser.
+