JeCabrera commited on
Commit
9b6b4fd
·
verified ·
1 Parent(s): 9a690ed

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -75
app.py CHANGED
@@ -1,83 +1,64 @@
1
- import streamlit as st
2
- import openai
3
- import os
4
 
5
- # Set up OpenAI API key
6
- openai.api_key = os.getenv("OPENAI_API_KEY")
7
 
8
- def generate_video_script(title, formality_level, emotional_tone, engagement_level):
9
- # Construct the original detailed prompt as provided
10
- prompt = (
11
- f"[Use this video framework below]\n"
12
- f"First we need to have a strong hook.\n"
13
- f"A short intro that stops people from scrolling and holds their attention\n"
14
- f"Example. \"{title}\"\n"
15
- f"Now we add in “The Setup\"\n"
16
- f"* This is used to Setup the scene and provide context to the Viewer\n"
17
- f"* ex. \"I've been creating videos recently and I guess something finally clicked\"\n"
18
- f"* This lets the viewer know that she’s been uploading more videos recently, and that could have led to an increase in views and followers.\n"
19
- f"ACT 2: \"The Conflict\"\n"
20
- f"* Introduce a point of conflict or problem that requires a solution\n"
21
- f"* ex. \"Some of you have been asking about scripting and storytelling and there's a lot to talk about, but I gotchu\"\n"
22
- f"* Setting up the foundation to lead to the topic of the video and posing the concern that 'there's a lot to talk about'\n"
23
- f"* Which opens the question of how we're going to tackle the topic in a limited amount of time\n"
24
- f"ACT 3: \"The Resolution\"\n"
25
- f"* Addressing the conflict we introduced and resolving it\n"
26
- f"* ex. \"Here's how I tell my stories. All you need are these 3: ACT I, ACT II, and ACT III.\"\n"
27
- f"* She proceeds to explain how we structure and tell our stories, which answers and resolves the initial conflict\n"
28
- f"A call to action or loop.\n"
29
- f"Call-To-Action\n"
30
- f"* After giving valuable information to your viewer, you have to be able to lead them somewhere or encourage them to engage\n"
31
- f"* ex. \"And if you wanna know how that looks like, then watch this video back and follow for more.\"\n"
32
- f"* This encourages the audience to rewatch the video to see the video is an actual example of what they just learned and it encourages them to follow and share the content if they found it valuable!\n"
33
- f"Follow viral video recipe above in creating a Viral Video script for me. Do not repeat the instructions above, just use the framework for the viral video script. Every output must include: HOOK, THE SETUP, THE CONFLICT, THE RESOLUTION, THE CTA. \n"
34
- f"Topic: {title}\n"
35
- f"Tone: {emotional_tone}\n"
36
- f"Formality Level: {formality_level}\n"
37
- f"Engagement Level: {engagement_level}"
38
  )
 
39
 
40
- try:
41
- response = openai.ChatCompletion.create(
42
- model="gpt-3.5-turbo",
43
- messages=[
44
- {"role": "system", "content": "Generate a script based on the following instructions."},
45
- {"role": "user", "content": prompt}
46
- ],
47
- temperature=0.7,
48
- max_tokens=1024,
49
- )
50
- # Accessing the generated script from the response
51
- script = response['choices'][0]['message']['content'].strip()
52
- return script
53
- except Exception as e:
54
- st.error(f"Failed to generate script: {str(e)}")
55
- return "Error in generating script."
56
 
57
- # Streamlit UI setup
58
- st.set_page_config(layout="wide")
59
- st.markdown("<h1 style='text-align: center; color: black;'>Viral Video Script Generator</h1>", unsafe_allow_html=True)
 
 
 
60
 
61
- # Create columns for input and output
62
- col1, col2 = st.columns([1, 2])
63
-
64
- with col1:
65
- st.markdown("<h2 style='text-align: center; color: black;'>Video Information</h2>", unsafe_allow_html=True)
66
- video_title = st.text_input("Title of Video", placeholder="Enter the title of your video/video idea")
67
- formality_level = st.selectbox("Formality Level", ["Casual", "Neutral", "Formal"])
68
- emotional_tone = st.selectbox("Emotional Tone", ["Positive", "Neutral", "Humorous"])
69
- engagement_level = st.selectbox("Engagement Level", ["Interactive", "Informative", "Persuasive"])
70
-
71
- with col2:
72
- st.markdown("<h2 style='text-align: center; color: black;'>Viral Script</h2>", unsafe_allow_html=True)
73
- st.markdown('**Note:** Fill out the fields on the left, then click Generate')
 
 
 
74
 
75
- generate_button = col1.button('Generate Video Script')
 
 
 
 
76
 
77
- if generate_button:
78
- if not video_title:
79
- st.error("Please enter the title of the video.")
80
- else:
81
- video_script = generate_video_script(video_title, formality_level, emotional_tone, engagement_level)
82
- with col2:
83
- st.write(video_script)
 
1
+ # app.py
2
+ import gradio as gr
3
+ import anthropic
4
 
5
+ # Configura el cliente de la API de Claude (Anthropic)
6
+ client = anthropic.Anthropic(api_key="my_api_key") # Reemplaza "my_api_key" con tu clave de API
7
 
8
+ def generate_headlines(number_of_headlines, target_audience, product):
9
+ # Llama a la API de Claude para generar titulares
10
+ message = client.messages.create(
11
+ model="claude-3-5-sonnet-20240620",
12
+ max_tokens=1000,
13
+ temperature=0,
14
+ system="You are a world-class copywriter, with experience in creating hooks, headlines, and subject lines that immediately capture attention. Your skill lies in deeply understanding the emotions, desires, and challenges of a specific audience, allowing you to design personalized marketing strategies that resonate and motivate action. You know how to use proven structures to attract your target audience, generating interest and achieving a powerful connection that drives desired results in advertising and content campaigns.\n\nAnswer in Spanish.",
15
+ messages=[
16
+ {
17
+ "role": "user",
18
+ "content": [
19
+ {
20
+ "type": "text",
21
+ "text": f"Generate {number_of_headlines} attention-grabbing headlines designed for {target_audience} to generate interest in {product}. Each headline should be crafted to encourage a specific action, such as making a purchase, signing up, or downloading. Use a variety of formats (questions, bold statements, intriguing facts) to test different approaches."
22
+ }
23
+ ]
24
+ }
25
+ ]
 
 
 
 
 
 
 
 
 
 
 
 
26
  )
27
+ return message.content
28
 
29
+ # Configura la interfaz de usuario con Gradio
30
+ def gradio_generate_headlines(number_of_headlines, target_audience, product):
31
+ return generate_headlines(number_of_headlines, target_audience, product)
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
+ # Define los colores de la interfaz según el logo de Anthropic (ejemplo)
34
+ logo_colors = {
35
+ "background": "#f8f8f8",
36
+ "primary": "#2c7be5",
37
+ "text_color": "#212529"
38
+ }
39
 
40
+ with gr.Blocks(css=".gradio-container { background-color: " + logo_colors["background"] + "; }") as demo:
41
+ gr.Markdown(
42
+ f"""
43
+ <h1 style="color: {logo_colors['primary']}; text-align: center;">Generador de Titulares</h1>
44
+ <p style="color: {logo_colors['text_color']}; text-align: center;">Usa el poder de Claude AI para crear titulares atractivos</p>
45
+ """
46
+ )
47
+
48
+ with gr.Row():
49
+ with gr.Column():
50
+ number_of_headlines = gr.Number(label="Número de Titulares", value=5)
51
+ target_audience = gr.Textbox(label="Público Objetivo", placeholder="Ejemplo: Estudiantes Universitarios")
52
+ product = gr.Textbox(label="Producto", placeholder="Ejemplo: Curso de Inglés")
53
+ submit_btn = gr.Button("Generar Titulares", elem_id="submit-btn")
54
+
55
+ output = gr.Textbox(label="Titulares Generados", lines=10)
56
 
57
+ submit_btn.click(
58
+ fn=gradio_generate_headlines,
59
+ inputs=[number_of_headlines, target_audience, product],
60
+ outputs=output
61
+ )
62
 
63
+ # Lanza la interfaz
64
+ demo.launch()