Team Ai
Apppublic

broductmanager/scriptmaven

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
app.py153 linesDownload Raw Back to root
1import streamlit as st2from langchain import PromptTemplate3from langchain.llms import OpenAI4import math5 6# LLM loading function7def load_LLM(openai_api_key):8    llm = OpenAI(openai_api_key=openai_api_key)9    return llm10 11 12# Generate content plan with GPT-313def generate_content_plan(llm, content_input, video_length, video_style, tone):14    prompt = f"""Generate a {content_type} {video_length}-minute long video content plan based on the article. Prioritize key insights and allocate time to each section based on its complexity, relevance to the overall topic, and fitting within the {video_length} time frame. Specify the time in seconds for each section. The article is as follows: {content_input}15    Make sure to distribute the time effectively among sections to ensure a balanced and informative video within the specified time limit.For sections, ensure that the total duration does not exceed {video_length}. the video is for {video_style} and users are {tone}16    Each section should be described as a JSON-like object: {{ "Title": "section_title", "Description": "description", "Duration": "duration in seconds" }}17 18 19 20 21    """22    content_plan = llm(prompt)23    return content_plan24# Generate detailed content for each section25def generate_detailed_content(llm, content_input, video_length, video_style, tone, content_type, content_plan):26    prompt = f"""Based on the content plan provided below, create a detailed script for a {video_length}-minute video:27    Content Plan: {content_plan}28 29    Please note:30    - 'Title' refers to the title of the section.31    - 'Description' refers to a brief overview of the section.32    - 'Duration' refers to the time allocated to each section in seconds.33 34    The script should include:35    - Introductory lines for each section36    - Key points for each section37    - Data or examples to support key points38    - Transitions between sections39    - A closing statement40 41    Additional Context:42    - Content Type: {content_type}43    - Video Style: {video_style}44    - Target Audience: {tone}45    - Base Article: {content_input}46    """47    48    detailed_content = llm(prompt)49    return detailed_content50 51 52 53# ... Your existing functions54 55# Streamlit UI56 57# Streamlit UI58st.set_page_config(page_title="ScriptMaven📜🧠", page_icon=":robot:")59st.header("Script:red[Maven] 📜🧠")60st.subheader("Your Edu-Video Blueprint", divider='rainbow')61st.write("Automate and optimize your educational video scripting with ScriptMaven. Leveraging OpenAI's GPT-4, it transforms raw text into structured video scripts tailored for various audiences and styles.")62# Add the Side Panel63st.sidebar.header('Product Description')64st.sidebar.markdown("""65**Key Features:**66- Multiple video styles and tones.67- Adjustable video lengths.68- Varied content types.69""")70st.sidebar.header("Who's it for?")71st.sidebar.markdown("""72- Content Creators73- Corporate Trainers74- Educational Institutions75""")76 77st.sidebar.header('How to Use:')78st.sidebar.markdown("""79[Get your OpenAI API Key from here](https://platform.openai.com/signup)801. **API Key**: Enter OpenAI API key.812. **Style & Tone**: Select from options.823. **Video Length & Type**: Choose.834. **Raw Content**: Paste.845. **Generate Plan**: Click.856. **Review & Finalize**: Obtain the script.86""")87# icons88# Add Font Awesome CSS89st.markdown("""90    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">91    """, unsafe_allow_html=True)92 93# ... Existing code for sidebar and Font Awesome inclusion94 95# Add social media icons at the bottom96st.sidebar.markdown('---')  # Horizontal line for separation97st.sidebar.markdown("### Socials:")98st.sidebar.markdown("""99<div style="display: flex; flex-direction: row; align-items: center;">100    <a href="https://github.com/pathakmukul" target="_blank" style="margin-right: 20px; text-decoration: none;">101        <i class="fab fa-github fa-2x" style="color: white;"></i>102    </a>103    <a href="https://twitter.com/twitter" target="_blank" style="margin-right: 20px; text-decoration: none;">104        <i class="fab fa-twitter fa-2x" style="color: inherit;"></i>105    </a>106    <a href="https://huggingface.co/broductmanager" target="_blank" style="font-size: 28px; text-decoration: none; color: inherit;">107        🤗108    </a>109</div>110""", unsafe_allow_html=True)111 112# f113# Create columns for the API Key input and the Get Key link114 115openai_api_key = st.text_input("OpenAI API Key", placeholder="Ex: sk-2twmA8tfCb8un4...")116# Create 2x2 grid for the select boxes117col1, col2 = st.columns(2)118with col1:119    video_style = st.selectbox('Video Style:', ('YouTube', 'Corporate'))120    video_length = st.selectbox('Video Length(minutes):', ('3','5', '10', '15'))121 122with col2:123    tone = st.selectbox('Audience:', ('School Students', 'College Students', 'Employee', 'For Teens'))124    content_type = st.selectbox('Content Type:', ('Case Study', 'Masterclass', 'Documentary', 'How-to Videos', 'Coding', 'Summary', 'Review'))125 126# Text area below the 2x2 grid127content_input = st.text_area("Content Input", placeholder="Your content deserves to be here 👑 ")128 129 130# Generate plan button131# ...132# Generate Content Plan Button133if st.button("Generate Plan"):134    llm = load_LLM(openai_api_key=openai_api_key)135    content_plan = generate_content_plan(llm, content_input, video_length, video_style, tone)136 137    # Display the generated plan138    st.write("Generated Content Plan:")139    st.write(content_plan)140 141    # Pass the generated content_plan directly into the next prompt142    detailed_content = generate_detailed_content(llm, content_plan, content_input, video_length, video_style, tone, content_type)143    144    st.write("Generated Detailed Scripts:")145    st.write(detailed_content)146    147    148# Add footer149st.markdown(150    # "<div style='text-align: center;'>Made with <span style='color: red;'>&hearts;</span> by Mukul.</div>",151    unsafe_allow_html=True,152)153