Bharathsekhar commited on
Commit
5a38c1b
Β·
verified Β·
1 Parent(s): 777d251

Upload app.py.py

Browse files
Files changed (1) hide show
  1. app.py.py +52 -0
app.py.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from langchain_google_genai import ChatGoogleGenerativeAI # Correct Import
3
+ from dotenv import load_dotenv
4
+ import os
5
+
6
+ # Load API key from .env file
7
+ load_dotenv()
8
+ API_KEY = os.getenv("GEMINI_API_KEY")
9
+
10
+ # Initialize LangChain's ChatGoogleGenerativeAI
11
+ llm = ChatGoogleGenerativeAI(model="gemini-1.5-pro", google_api_key=API_KEY)
12
+
13
+ # Function to process and format the AI output
14
+ def format_output(text):
15
+ """Refine AI-generated text into a structured format."""
16
+ sections = text.split("**option") # Split into different options
17
+ formatted_text = ""
18
+
19
+ for section in sections:
20
+ if section.strip():
21
+ formatted_text += f"🟒 **Option {section.strip()}**\n\n" # Highlight each option
22
+ return formatted_text if formatted_text else "No output generated. Try again."
23
+
24
+ # Function to generate AI content using LangChain
25
+ def generate_marketing_content(prompt):
26
+ """Generate marketing content using LangChain's ChatGoogleGenerativeAI."""
27
+ try:
28
+ response = llm.invoke(prompt) # Use invoke() instead of predict()
29
+ return format_output(response.content) # Extract text correctly
30
+ except Exception as e:
31
+ return f"❌ Error: {str(e)}"
32
+
33
+ # Streamlit UI
34
+ st.set_page_config(page_title="AI Marketing Generator", layout="wide")
35
+ st.title("πŸš€ AI Marketing Generator")
36
+ st.write("Generate high-quality marketing slogans, ad copy, and campaign ideas instantly!")
37
+
38
+ # User Inputs
39
+ category = st.selectbox("Select Content Type", ["Slogan", "Ad Copy", "Campaign Idea"])
40
+ tone = st.selectbox("Select Tone", ["Energetic ⚑", "Professional πŸ‘”", "Fun πŸŽ‰"])
41
+ product = st.text_input("Enter Product Name")
42
+
43
+ if st.button("🎯 Generate Marketing Content"):
44
+ if product:
45
+ prompt = f"Generate a {tone.split()[0].lower()} {category.lower()} for the following product: {product}."
46
+ output = generate_marketing_content(prompt)
47
+
48
+ st.success("βœ… Content Generated Successfully!")
49
+ st.subheader("πŸ“Œ **Generated Content**:")
50
+ st.markdown(output, unsafe_allow_html=True)
51
+ else:
52
+ st.warning("⚠️ Please enter a product description.")