nniehaus commited on
Commit
c561261
·
1 Parent(s): 6ff2402

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -43
app.py CHANGED
@@ -1,59 +1,33 @@
1
  import streamlit as st
2
  import openai
3
- import requests
4
- from PIL import Image
5
- from io import BytesIO
6
 
7
  # Access the OpenAI API key from Hugging Face Spaces secrets
8
  openai.api_key = st.secrets["OPENAI_API_KEY"]
9
 
10
- st.title("Children's Story and Image Panel Generator")
11
 
12
- # User inputs for the story and main character
13
- age_group = st.selectbox("Age Group", ["3-5 years", "6-8 years", "9-12 years"])
14
- theme = st.text_input("Story Theme", placeholder="Enter a theme for the story (e.g., adventure, friendship)")
15
- main_character = st.text_input("Main Character", placeholder="Describe the main character (e.g., a small brave rabbit)")
16
- details = st.text_area("Additional Details", placeholder="Any specific details to include in the story (e.g., a magical forest)")
 
17
 
18
- # Function to generate the story
19
- def generate_story(age_group, theme, main_character, details):
20
- prompt = f"Write a concise children's story suitable for age group {age_group} about {theme} featuring a main character who is {main_character}. Include details such as {details}. The story should be short enough to fit within 10 panels."
21
  response = openai.ChatCompletion.create(
22
  model="gpt-4",
23
  messages=[
24
- {"role": "system", "content": "You are a creative writer."},
25
  {"role": "user", "content": prompt}
26
  ],
27
- max_tokens=300 # Adjust the token limit as needed
28
  )
29
  return response.choices[0].message['content']
30
 
31
- # Function to generate images with DALL-E 3
32
- def generate_image(panel_text, main_character):
33
- try:
34
- prompt = f"{panel_text}. Visual style: consistent with previous panels. Main character: {main_character}."
35
- response = openai.Image.create(
36
- prompt=prompt,
37
- n=1,
38
- size="1024x1024", # Adjust the size if needed
39
- model="dall-e-3" # Specify DALL-E 3 model
40
- )
41
- image_url = response['data'][0]['url']
42
- image_response = requests.get(image_url)
43
- image = Image.open(BytesIO(image_response.content))
44
- return image
45
- except Exception as e:
46
- st.error(f"Error in generating image: {e}")
47
- return None
48
-
49
- if st.button('Generate Story and Images'):
50
- story = generate_story(age_group, theme, main_character, details)
51
- story_parts = story.split('.')[:10] # Use the first 10 sentences for panels
52
-
53
- for i, part in enumerate(story_parts):
54
- if part.strip(): # Ensure part is not empty
55
- st.subheader(f'Panel {i+1}')
56
- st.write(part.strip())
57
- image = generate_image(part, main_character)
58
- if image:
59
- st.image(image, caption=f'Image for Panel {i+1}')
 
1
  import streamlit as st
2
  import openai
3
+ import os
 
 
4
 
5
  # Access the OpenAI API key from Hugging Face Spaces secrets
6
  openai.api_key = st.secrets["OPENAI_API_KEY"]
7
 
8
+ st.title("2024 Lead Generation Plan Creator for Small Businesses")
9
 
10
+ # User inputs for creating the lead generation plan
11
+ st.subheader("Tell Us About Your Business")
12
+ business_description = st.text_area("Business Description", placeholder="Describe your business (e.g., nature, services/products, size).")
13
+ target_customers = st.text_area("Target Customers", placeholder="Describe your ideal customers (e.g., demographics, interests, locations).")
14
+ advertising_budget = st.selectbox("Advertising Budget", ["No budget", "Limited budget", "Moderate budget", "Large budget"])
15
+ additional_details = st.text_area("Additional Details", placeholder="Any specific goals or strategies you've considered?")
16
 
17
+ # Function to generate the lead generation plan
18
+ def generate_lead_generation_plan(business_description, target_customers, advertising_budget, additional_details):
19
+ prompt = f"Create a detailed lead generation plan for 2024 for a business described as follows: {business_description}. The target customers are: {target_customers}. The advertising budget is: {advertising_budget}. Additional details: {additional_details}. Include step-by-step instructions and strategies for implementing lead generation systems."
20
  response = openai.ChatCompletion.create(
21
  model="gpt-4",
22
  messages=[
23
+ {"role": "system", "content": "You are a marketing expert."},
24
  {"role": "user", "content": prompt}
25
  ],
26
+ max_tokens=500 # Adjust the token limit as needed
27
  )
28
  return response.choices[0].message['content']
29
 
30
+ if st.button('Generate Lead Generation Plan'):
31
+ plan = generate_lead_generation_plan(business_description, target_customers, advertising_budget, additional_details)
32
+ st.subheader("Your Customized Lead Generation Plan for 2024:")
33
+ st.write(plan)