Spaces:
Sleeping
Sleeping
| # # script_gen.py | |
| # import os | |
| # import asyncio | |
| # import httpx | |
| # import logging | |
| # from dotenv import load_dotenv | |
| # dotenv_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), '.env') | |
| # load_dotenv(dotenv_path) | |
| # logging.basicConfig(level=logging.INFO, format="%(asctime)s [%(levelname)s] %(message)s") | |
| # OPENROUTER_API_KEY = os.getenv("OPENROUTER_API_KEY") | |
| # MODEL_NAME = "deepseek/deepseek-r1-distill-llama-70b:free" | |
| # OPENROUTER_URL = f"https://openrouter.ai/api/v1/chat/completions" | |
| # async def generate_script(idea: str) -> str: | |
| # """ | |
| # Generate a highly interactive ad script from user idea. | |
| # Includes detailed expressions, actions, and minute details. | |
| # """ | |
| # prompt = f""" | |
| # You are a professional ad writer. | |
| # Take this idea and generate a fun, interactive, and detailed ad script. | |
| # Include **minute expressions, subtle actions, emotions, and character reactions**. | |
| # Idea: {idea} | |
| # The script should be ready for storyboard creation. | |
| # """ | |
| # headers = {"Authorization": f"Bearer {OPENROUTER_API_KEY}"} | |
| # payload = { | |
| # "model": MODEL_NAME, | |
| # "messages": [{"role": "user", "content": prompt}], | |
| # "temperature": 0.8, | |
| # "max_tokens": 1200 | |
| # } | |
| # async with httpx.AsyncClient(timeout=120) as client: | |
| # response = await client.post(OPENROUTER_URL, json=payload, headers=headers) | |
| # response.raise_for_status() | |
| # data = response.json() | |
| # script = data["choices"][0]["message"]["content"] | |
| # logging.info("Script generated successfully") | |
| # return script | |
| # script_gen.py | |
| import os | |
| import asyncio | |
| import httpx | |
| import logging | |
| from dotenv import load_dotenv | |
| dotenv_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), '.env') | |
| load_dotenv(dotenv_path) | |
| logging.basicConfig(level=logging.INFO, format="%(asctime)s [%(levelname)s] %(message)s") | |
| OPENROUTER_API_KEY = os.getenv("OPENROUTER_API_KEY") | |
| MODEL_NAME = "deepseek/deepseek-r1-distill-llama-70b:free" | |
| OPENROUTER_URL = "https://openrouter.ai/api/v1/chat/completions" | |
| async def generate_script(idea: str) -> str: | |
| """ | |
| Generate a short, funny, no-dialogue ad script based on a user idea. | |
| The script should be written in plain text — simple narrative form, | |
| no markdown, no camera angles, and no stage directions. | |
| Just like: | |
| A guy sits in a quiet library. He slowly opens a packet of Lay’s... | |
| """ | |
| prompt = f""" | |
| You are a creative ad script writer. | |
| Write a short, funny, no-dialogue ad script from this idea: "{idea}". | |
| Keep it simple and cinematic. | |
| Use plain text only, with minimal expressions. | |
| No markdown, no numbering, no headings, no scene titles. | |
| Just write it like a mini story in clean text form. | |
| """ | |
| headers = {"Authorization": f"Bearer {OPENROUTER_API_KEY}"} | |
| payload = { | |
| "model": MODEL_NAME, | |
| "messages": [{"role": "user", "content": prompt}], | |
| "temperature": 0.8, | |
| "max_tokens": 600 | |
| } | |
| async with httpx.AsyncClient(timeout=120) as client: | |
| response = await client.post(OPENROUTER_URL, json=payload, headers=headers) | |
| response.raise_for_status() | |
| data = response.json() | |
| script = data["choices"][0]["message"]["content"].strip() | |
| logging.info("Simple script generated successfully") | |
| return script | |
| # Example usage (for testing) | |
| # asyncio.run(generate_script("Lay’s funny ad in a library with no dialogues")) | |