WIP - UI, firecrawl, long-form - V0.5

This commit is contained in:
ajaysi
2024-06-17 16:29:38 +05:30
parent dc8893113a
commit 3563ac29cb
3 changed files with 70 additions and 46 deletions

View File

@@ -98,3 +98,29 @@ def write_blog_from_keywords(search_keywords, url=None):
st.image(generated_image_filepath)
st.markdown(f"{blog_markdown_str}")
status.update(label=f"Finished, Review & Use your Original Content Below: {saved_blog_to_file}", state="complete")
# Display options below the content
col1, col2, col3, col4, col5 = st.columns(5)
if col1.button('Copy'):
pyperclip.copy(blog_markdown_str)
st.success("Text copied to clipboard!")
if col2.button('Rephrase'):
rephrased_text = rephrase_text(blog_markdown_str)
st.markdown(rephrased_text)
if col3.button('Change Tone'):
tone = st.selectbox("Select Tone", ["Formal", "Casual", "Professional"])
if st.button("Apply Tone"):
toned_text = change_tone(blog_markdown_str, tone)
st.markdown(toned_text)
if col4.button('Make Shorter'):
shorter_text = make_shorter(blog_markdown_str)
st.markdown(shorter_text)
if col5.button('Translate'):
language = st.selectbox("Select Language", ["Spanish", "French", "German"])
if st.button("Translate"):
translated_text = translate_text(blog_markdown_str, language)
st.markdown(translated_text)

View File

@@ -126,13 +126,13 @@ def long_form_generator(content_keywords):
generation_config = {
"temperature": 0.6,
"top_p": 1,
"max_output_tokens": 4096,
"max_output_tokens": 8096,
}
genai.configure(api_key=os.getenv('GEMINI_API_KEY'))
# Initialize the generative model
model = genai.GenerativeModel('gemini-pro', generation_config=generation_config)
model_pro = genai.GenerativeModel('gemini-1.5-flash-latest', generation_config=generation_config)
#model = genai.GenerativeModel('gemini-pro', generation_config=generation_config)
model_pro = genai.GenerativeModel('gemini-1.5-flash', generation_config=generation_config)
# Do SERP web research for given keywords to generate title and outline.
web_research_result, g_titles = do_google_serp_search(content_keywords)
@@ -185,7 +185,7 @@ def long_form_generator(content_keywords):
try:
logger.info(f"Starting to write on the outline introduction.")
draft = starting_draft
continuation = generate_with_retry(model, continuation_prompt.format(
continuation = generate_with_retry(model_pro, continuation_prompt.format(
content_title=content_title,
content_outline=content_outline,
content_text=draft,
@@ -203,7 +203,7 @@ def long_form_generator(content_keywords):
logger.info(f"Writing in progress... Current draft length: {len(draft)} characters")
status.update(label=f"Writing in progress... Current draft length: {len(draft)} characters")
search_terms = f"""
I will provide you with blog outline, your task is to read the outline & return 3 google search keywords.
I will provide you with blog outline, your task is to read the outline & return 8 google search keywords.
Your response will be used to do web research for writing on the given outline.
Do not explain your response, provide 8 google search sentences encompassing the given content outline.
Provide the search term results as comma separated values.\n\n
@@ -214,30 +214,29 @@ def long_form_generator(content_keywords):
status.update(label=f"Search terms from written draft: {search_words}")
while 'IAMDONE' not in continuation:
try:
#web_research_result, m_titles = do_metaphor_ai_research(content_keywords)
str_list = re.split(r',\s*', search_words)
# Strip quotes from each element
str_list = [s.strip('\'"') for s in str_list]
for search_term in str_list:
web_research_result, m_titles, t_titles = do_tavily_ai_search(search_term, max_results=5)
continuation = generate_with_retry(model, continuation_prompt.format(
#web_research_result, m_titles = do_metaphor_ai_research(content_keywords)
str_list = re.split(r',\s*', search_words)
# Strip quotes from each element
str_list = [s.strip('\'"') for s in str_list]
for search_term in str_list:
web_research_result, m_titles, t_titles = do_tavily_ai_search(search_term, max_results=5)
try:
continuation = generate_with_retry(model_pro, continuation_prompt.format(
content_title=content_title,
content_outline=content_outline,
content_text=draft,
web_research_result=web_research_result,
writing_guidelines=writing_guidelines)).text
draft += '\n\n' + continuation
logger.info(f"Writing in progress... Current draft length: {len(draft)} characters")
status.update(label=f"Writing in progress... Current draft length: {len(draft)} characters")
# At this point, the context is little stale. We should more web research on
# related queries as per the content outline, to augment the LLM context.
except Exception as err:
st.error(f"Failed to continually write the Essay: {err}")
logger.error(f"Failed to continually write the Essay: {err}")
return
draft += '\n\n' + continuation
logger.info(f"Writing in progress... Current draft length: {len(draft)} characters")
status.update(label=f"Writing in progress... Current draft length: {len(draft)} characters")
# At this point, the context is little stale. We should more web research on
# related queries as per the content outline, to augment the LLM context.
except Exception as err:
st.error(f"Failed to continually write the Essay: {err}")
logger.error(f"Failed to continually write the Essay: {err}")
return
# Remove 'IAMDONE' and print the final story
final = draft.replace('IAMDONE', '').strip()