nniehaus commited on
Commit
862456a
·
verified ·
1 Parent(s): ce0ea95

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -45
app.py CHANGED
@@ -1,53 +1,63 @@
1
  import streamlit as st
2
  import openai
3
 
4
- # Access the OpenAI API key from Hugging Face Spaces secrets or your environment variables
5
- openai.api_key = st.secrets["OPENAI_API_KEY"]
6
-
7
- st.title("Video Script Generator")
8
-
9
- # Define video styles and their descriptions
10
- video_styles = {
11
- "Explainer": "Explainer videos break down complex concepts into simple, engaging visuals and narratives.",
12
- "Testimonial": "Testimonial videos feature satisfied customers sharing their positive experiences.",
13
- "Product Demo": "Product demos showcase the features and benefits of a product in action.",
14
- "How-To": "How-to videos provide step-by-step instructions on performing a task or using a product.",
15
- "Brand Story": "Brand story videos share the company's mission, vision, and values, connecting emotionally with the audience."
16
- }
17
-
18
- # User selects the video style
19
- video_style = st.selectbox("Choose the style of video you want to create:", options=list(video_styles.keys()))
20
 
21
- # Display the description of the selected video style
22
- st.write(f"**Description:** {video_styles[video_style]}")
23
-
24
- # Additional inputs
25
- business_name = st.text_input("Business Name", "Your Business Name")
26
- target_audience = st.text_area("Target Audience", "Describe your target audience.")
27
 
28
- # Button to generate video script
29
- if st.button('Generate Video Script'):
30
- # Construct the prompt for the AI
31
- prompt_text = f"Create a script for a {video_style.lower()} video for '{business_name}' targeting '{target_audience}'. {video_styles[video_style]}"
32
-
33
- # Call the OpenAI API for text generation
34
  try:
35
- response = openai.Completion.create(
36
- engine="text-davinci-003",
37
- prompt=prompt_text,
38
- max_tokens=500,
39
- temperature=0.7,
40
- top_p=1,
41
- frequency_penalty=0,
42
- presence_penalty=0
 
43
  )
44
- script = response.choices[0].text.strip()
45
  except Exception as e:
46
- script = f"Error in generating script: {e}"
47
-
48
- # Display the generated script
49
- st.markdown("### Generated Video Script")
50
- st.write(script)
51
-
52
- # Disclaimer
53
- st.write("Disclaimer: This tool provides AI-generated suggestions. Please review and customize the script to fit your specific business needs.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
  import openai
3
 
4
+ # Initializing Streamlit app
5
+ st.title("Video Script Generator for Small Businesses")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
+ # Accessing the OpenAI API key securely
8
+ openai.api_key = st.secrets["OPENAI_API_KEY"]
 
 
 
 
9
 
10
+ # Function to call OpenAI API
11
+ def call_openai_api(prompt):
 
 
 
 
12
  try:
13
+ response = openai.ChatCompletion.create(
14
+ model="gpt-4",
15
+ messages=[
16
+ {
17
+ "role": "system",
18
+ "content": prompt['system']
19
+ },
20
+ {"role": "user", "content": prompt['user']}
21
+ ]
22
  )
23
+ return response.choices[0].message['content']
24
  except Exception as e:
25
+ st.error(f"An error occurred: {str(e)}")
26
+ return None
27
+
28
+ # Streamlit UI for input
29
+ business_description = st.text_area("Describe your business or video topic/idea:", placeholder="e.g., We are a local bakery specializing in gluten-free pastries.")
30
+ problem_solved = st.text_input("What problem do you solve for your customers?", placeholder="e.g., Making gluten-free living delicious and easy.")
31
+ services_offered = st.text_input("What services do you want to mention in your video?", placeholder="e.g., Custom gluten-free cakes for special occasions.")
32
+ unique_aspects = st.text_input("What makes you unique or separates you from others in your industry?", placeholder="e.g., Our secret family recipes.")
33
+ name_to_include = st.text_input("List any names (your name or business name) you want to include in the video.", placeholder="e.g., 123 Custom Blinds or Mary Smith")
34
+ call_to_action = st.text_input("How do you want to be contacted? (Provide one call to action)", placeholder="e.g., Visit our bakery on Main Street.")
35
+ script_length = st.number_input("Desired script length (maximum word count):", min_value=50, max_value=250, value=150, step=10)
36
+
37
+ generate_button = st.button('Generate Video Script')
38
+
39
+ # Handling button click
40
+ if generate_button:
41
+ # Creating the prompt as a dictionary
42
+ user_prompt = {
43
+ "system": """
44
+ Act as a small business marketing video script writer. You respond with fully written video scripts that contain only the words that should be read out
45
+ loud into the camera. The scripts you create do not include shot directions, references to who is speaking, or any other extraneous notes that are not the actual
46
+ words that should be read out loud. As a small business video marketing expert, you have studied the most effective marketing and social media videos made by small
47
+ businesses. The video scripts are short, always coming in under the specified maximum word count. They always begin with engaging opening lines that tease what the
48
+ rest of the video is about and they end with a single strong call to action.""",
49
+ "user": f"""
50
+ Industry: {business_description}
51
+ Problem Solved: {problem_solved}
52
+ Services Offered: {services_offered}
53
+ Unique Aspects: {unique_aspects}
54
+ Names to Include: {name_to_include}
55
+ Call to Action: {call_to_action}
56
+ Script Length: {script_length} words maximum."""
57
+ }
58
+ script = call_openai_api(user_prompt)
59
+ if script:
60
+ st.markdown("### Generated Video Script")
61
+ st.write(script)
62
+ else:
63
+ st.write("An error occurred while generating the script. Please try again.")