Joanna30's picture
Update utils.py
93423bf verified
raw
history blame
1.16 kB
import os
import google.generativeai as palm
from langchain.chains import LLMChain
from langchain.prompts import PromptTemplate
from langchain.tools import DuckDuckGoSearchRun
def generate_script(prompt, video_length, creativity, api_key):
# Configure Palm API
palm.configure(api_key=api_key)
# Fetch search data using DuckDuckGo
search_tool = DuckDuckGoSearchRun()
search_data = search_tool.run(prompt)
# Generate a title using Palm
title_response = palm.generate_text(
model="models/text-bison-001",
temperature=creativity,
prompt=f"Generate a YouTube video title for the topic: {prompt}"
)
title = title_response.result.strip()
# Generate a script using Palm
script_prompt = (
f"Create a YouTube script with the title '{title}' that lasts {video_length} minutes. "
f"Use the following search data for inspiration: {search_data}"
)
script_response = palm.generate_text(
model="models/text-bison-001",
temperature=creativity,
prompt=script_prompt
)
script = script_response.result.strip()
return title, script, search_data