File size: 3,514 Bytes
eb8c5e1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# # 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"))