Skip to content

Money text to video #749

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions app/controllers/v1/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ def generate_video_script(request: Request, body: VideoScriptRequest):
def generate_video_terms(request: Request, body: VideoTermsRequest):
video_terms = llm.generate_terms(
video_subject=body.video_subject,
video_script=body.video_script,
amount=body.amount,
video_script=body.video_script
)
response = {"video_terms": video_terms}
return utils.get_response(200, response)
33 changes: 20 additions & 13 deletions app/services/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ def generate_script(
4. you must not include any type of markdown or formatting in the script, never use a title.
5. only return the raw content of the script.
6. do not include "voiceover", "narrator" or similar indicators of what should be spoken at the beginning of each paragraph or line.
7. you must not mention the prompt, or anything about the script itself. also, never talk about the amount of paragraphs or lines. just write the script.
7. you must not mention the prompt, or anything about the script itself. also, never talk about the number of paragraphs or lines. just write the script.
8. respond in the same language as the video subject.

# Initialization:
Expand Down Expand Up @@ -365,18 +365,23 @@ def format_response(response):
return final_script.strip()


def generate_terms(video_subject: str, video_script: str, amount: int = 5) -> List[str]:
def generate_terms(video_subject: str, video_script: str) -> List[str]:
prompt = f"""
# Role: Video Search Terms Generator

## Goals:
Generate {amount} search terms for stock videos, depending on the subject of a video.

## Constrains:
1. the search terms are to be returned as a json-array of strings.
2. each search term should consist of 1-3 words, always add the main subject of the video.
3. you must only return the json-array of strings. you must not return anything else. you must not return the script.
4. the search terms must be related to the subject of the video.
# Role: AI Video Director and Editor

## Core Goal:
Analyze the provided complete video script and intelligently segment it into a sequence of logical scenes suitable for a short-form video. For each segmented scene, you must generate a highly descriptive English search query ideal for finding the most relevant stock footage on platforms like Pexels.

## Output Format and Constraints:
1. **You MUST return a pure, single JSON Array.** Do not include any explanatory text, markdown markers (` ```json ... ``` `), or any other content outside of the JSON array. Your entire response body must be a valid JSON array that can be parsed directly.
2. each search term should consist of 1-3 words, always add the main subject of the video.
3. Constraints for the `pexels_search_query` field value:
- It must be a concise, highly descriptive **English phrase**.
- It is intended to be used directly as the `query` parameter for the Pexels API.
- It should describe a concrete **visual scene**, not an abstract concept or emotion.
- **Excellent Examples**: "Man walking alone on foggy road", "Futuristic city skyline at night", "Close up of old book pages turning".
- **Poor Examples**: "sadness", "a trip", "the meaning of life".
4. Scene segmentation should be based on logical shifts in the narrative, changes in time, or natural transition points for visuals.
5. reply with english search terms only.

## Output Example:
Expand Down Expand Up @@ -437,8 +442,10 @@ def generate_terms(video_subject: str, video_script: str, amount: int = 5) -> Li
print("######################")
print(script)
search_terms = generate_terms(
video_subject=video_subject, video_script=script, amount=5
video_subject=video_subject, video_script=script
)
print("######################")
print(search_terms)
print("-----输出包含的场景数量-----")
print(len(search_terms))

2 changes: 1 addition & 1 deletion app/services/material.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def search_videos_pexels(
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36",
}
# Build URL
params = {"query": search_term, "per_page": 20, "orientation": video_orientation}
params = {"query": search_term, "per_page": 20, "orientation": video_orientation,"orientation":"landscape","size":"large"}
query_url = f"https://api.pexels.com/videos/search?{urlencode(params)}"
logger.info(f"searching videos: {query_url}, with proxies: {config.proxy}")

Expand Down
2 changes: 1 addition & 1 deletion app/services/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def generate_terms(task_id, params, video_script):
video_terms = params.video_terms
if not video_terms:
video_terms = llm.generate_terms(
video_subject=params.video_subject, video_script=video_script, amount=5
video_subject=params.video_subject, video_script=video_script
)
else:
if isinstance(video_terms, str):
Expand Down