Spaces:
No application file
No application file
Upload 8 files
Browse files- .env +1 -0
- .gitattributes +1 -0
- README.md +1 -13
- config.json +1 -0
- gemini_utility.cpython-312.pyc +0 -0
- gemini_utility.py +64 -0
- main.py +220 -0
- requirements.txt +4 -0
- test_image.png +3 -0
.env
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{ "GOOGLE_API_KEY": "AIzaSyAHd1zIOKcXM8xJPt4T-F55jN00u_4Phlw" }
|
.gitattributes
CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
test_image.png filter=lfs diff=lfs merge=lfs -text
|
README.md
CHANGED
@@ -1,13 +1 @@
|
|
1 |
-
|
2 |
-
title: Kashif
|
3 |
-
emoji: π’
|
4 |
-
colorFrom: red
|
5 |
-
colorTo: indigo
|
6 |
-
sdk: streamlit
|
7 |
-
sdk_version: 1.32.2
|
8 |
-
app_file: app.py
|
9 |
-
pinned: false
|
10 |
-
license: apache-2.0
|
11 |
-
---
|
12 |
-
|
13 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
+
# code-prep-gemini-ai-course
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
config.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{ "GOOGLE_API_KEY": "AIzaSyAHd1zIOKcXM8xJPt4T-F55jN00u_4Phlw" }
|
gemini_utility.cpython-312.pyc
ADDED
Binary file (2.02 kB). View file
|
|
gemini_utility.py
ADDED
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import json
|
3 |
+
from PIL import Image
|
4 |
+
|
5 |
+
import google.generativeai as genai
|
6 |
+
|
7 |
+
# working directory path
|
8 |
+
working_dir = os.path.dirname(os.path.abspath(__file__))
|
9 |
+
|
10 |
+
# path of config_data file
|
11 |
+
config_file_path = f"{working_dir}/config.json"
|
12 |
+
config_data = json.load(open("config.json"))
|
13 |
+
|
14 |
+
# loading the GOOGLE_API_KEY
|
15 |
+
GOOGLE_API_KEY = config_data["GOOGLE_API_KEY"]
|
16 |
+
|
17 |
+
# configuring google.generativeai with API key
|
18 |
+
genai.configure(api_key=GOOGLE_API_KEY)
|
19 |
+
|
20 |
+
|
21 |
+
def load_gemini_pro_model():
|
22 |
+
gemini_pro_model = genai.GenerativeModel("gemini-pro")
|
23 |
+
return gemini_pro_model
|
24 |
+
|
25 |
+
|
26 |
+
# get response from Gemini-Pro-Vision model - image/text to text
|
27 |
+
def gemini_pro_vision_response(prompt, image):
|
28 |
+
gemini_pro_vision_model = genai.GenerativeModel("gemini-pro-vision")
|
29 |
+
response = gemini_pro_vision_model.generate_content([prompt, image])
|
30 |
+
result = response.text
|
31 |
+
return result
|
32 |
+
|
33 |
+
|
34 |
+
# get response from embeddings model - text to embeddings
|
35 |
+
def embeddings_model_response(input_text):
|
36 |
+
embedding_model = "models/embedding-001"
|
37 |
+
embedding = genai.embed_content(model=embedding_model,
|
38 |
+
content=input_text,
|
39 |
+
task_type="retrieval_document")
|
40 |
+
embedding_list = embedding["embedding"]
|
41 |
+
return embedding_list
|
42 |
+
|
43 |
+
|
44 |
+
# get response from Gemini-Pro model - text to text
|
45 |
+
def gemini_pro_response(user_prompt):
|
46 |
+
gemini_pro_model = genai.GenerativeModel("gemini-pro")
|
47 |
+
response = gemini_pro_model.generate_content(user_prompt)
|
48 |
+
result = response.text
|
49 |
+
return result
|
50 |
+
|
51 |
+
|
52 |
+
# result = gemini_pro_response("What is Machine Learning")
|
53 |
+
# print(result)
|
54 |
+
# print("-"*50)
|
55 |
+
#
|
56 |
+
#
|
57 |
+
# image = Image.open("test_image.png")
|
58 |
+
# result = gemini_pro_vision_response("Write a short caption for this image", image)
|
59 |
+
# print(result)
|
60 |
+
# print("-"*50)
|
61 |
+
#
|
62 |
+
#
|
63 |
+
# result = embeddings_model_response("Machine Learning is a subset of Artificial Intelligence")
|
64 |
+
# print(result)
|
main.py
ADDED
@@ -0,0 +1,220 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
|
3 |
+
from PIL import Image
|
4 |
+
import streamlit as st
|
5 |
+
from streamlit_option_menu import option_menu
|
6 |
+
|
7 |
+
from gemini_utility import (load_gemini_pro_model,
|
8 |
+
gemini_pro_response,
|
9 |
+
gemini_pro_vision_response,
|
10 |
+
embeddings_model_response)
|
11 |
+
|
12 |
+
|
13 |
+
working_dir = os.path.dirname(os.path.abspath(__file__))
|
14 |
+
|
15 |
+
st.set_page_config(
|
16 |
+
page_title="Gemini AI",
|
17 |
+
page_icon="π§ ",
|
18 |
+
layout="centered",
|
19 |
+
)
|
20 |
+
|
21 |
+
with st.sidebar:
|
22 |
+
selected = option_menu('Gemini AI',
|
23 |
+
['Marketing Campaign',
|
24 |
+
'ChatBot',
|
25 |
+
'Image Captioning',
|
26 |
+
'Embed text',
|
27 |
+
'Ask me anything'],
|
28 |
+
menu_icon='robot', icons=['chat-dots-fill', 'image-fill', 'textarea-t', 'patch-question-fill'],
|
29 |
+
default_index=0
|
30 |
+
)
|
31 |
+
|
32 |
+
|
33 |
+
# Function to translate roles between Gemini-Pro and Streamlit terminology
|
34 |
+
def translate_role_for_streamlit(user_role):
|
35 |
+
if user_role == "model":
|
36 |
+
return "assistant"
|
37 |
+
else:
|
38 |
+
return user_role
|
39 |
+
|
40 |
+
|
41 |
+
|
42 |
+
# Marketing Campaign section
|
43 |
+
if selected == "Marketing Campaign":
|
44 |
+
st.title("π’ Marketing Campaign")
|
45 |
+
|
46 |
+
#product_name = st.text_input("Product Name", " ")
|
47 |
+
product_name = st.text_input(
|
48 |
+
"What is the name of the product? \n\n", key="product_name", value=" "
|
49 |
+
)
|
50 |
+
product_category = st.radio(
|
51 |
+
"Select your product category: \n\n",
|
52 |
+
["Clothing", "Electronics", "Food", "Health & Beauty", "Home & Garden"],
|
53 |
+
key="product_category",
|
54 |
+
horizontal=True,
|
55 |
+
)
|
56 |
+
target_audience = st.selectbox("Target Audience", ["Teens", "Adults", "Seniors"])
|
57 |
+
st.write("Select your target audience: ")
|
58 |
+
target_audience_age = st.radio(
|
59 |
+
"Target age: \n\n",
|
60 |
+
["18-24", "25-34", "35-44", "45-54", "55-64", "65+"],
|
61 |
+
key="target_audience_age",
|
62 |
+
horizontal=True,
|
63 |
+
)
|
64 |
+
#target_audience_gender = st.radio("Target gender: \n\n",["male","female","trans","non-binary","others"],key="target_audience_gender",horizontal=True)
|
65 |
+
target_audience_location = st.radio(
|
66 |
+
"Target location: \n\n",
|
67 |
+
["Urban", "Suburban", "Rural"],
|
68 |
+
key="target_audience_location",
|
69 |
+
horizontal=True,
|
70 |
+
)
|
71 |
+
campaign_objective = st.multiselect("Campaign Objective", ["Awareness", "Engagement", "Conversion"], default=["Awareness"])
|
72 |
+
#budget = st.slider("Budget", 1000, 10000, step=500, value=5000)
|
73 |
+
|
74 |
+
#--------------------------------------------------------------
|
75 |
+
st.write("Select your marketing campaign goal: ")
|
76 |
+
campaign_goal = st.multiselect(
|
77 |
+
"Select your marketing campaign goal: \n\n",
|
78 |
+
[
|
79 |
+
"Increase brand awareness",
|
80 |
+
"Generate leads",
|
81 |
+
"Drive sales",
|
82 |
+
"Improve brand sentiment",
|
83 |
+
],
|
84 |
+
key="campaign_goal",
|
85 |
+
default=["Increase brand awareness", "Generate leads"],
|
86 |
+
)
|
87 |
+
if campaign_goal is None:
|
88 |
+
campaign_goal = ["Increase brand awareness", "Generate leads"]
|
89 |
+
brand_voice = st.radio(
|
90 |
+
"Select your brand voice: \n\n",
|
91 |
+
["Formal", "Informal", "Serious", "Humorous"],
|
92 |
+
key="brand_voice",
|
93 |
+
horizontal=True,
|
94 |
+
)
|
95 |
+
estimated_budget = st.radio(
|
96 |
+
"Select your estimated budget ($): \n\n",
|
97 |
+
["1,000-5,000", "5,000-10,000", "10,000-20,000", "20,000+"],
|
98 |
+
key="estimated_budget",
|
99 |
+
horizontal=True,
|
100 |
+
)
|
101 |
+
|
102 |
+
prompt = f"""Generate a marketing campaign for {product_name}, a {product_category} designed for the age group: {target_audience_age}.
|
103 |
+
The target location is this: {target_audience_location}.
|
104 |
+
Aim to primarily achieve {campaign_goal}.
|
105 |
+
Emphasize the product's unique selling proposition while using a {brand_voice} tone of voice.
|
106 |
+
Allocate the total budget of {estimated_budget}.
|
107 |
+
With these inputs, make sure to follow following guidelines and generate the marketing campaign with proper headlines: \n
|
108 |
+
- Briefly describe company, its values, mission, and target audience.
|
109 |
+
- Highlight any relevant brand guidelines or messaging frameworks.
|
110 |
+
- Provide a concise overview of the campaign's objectives and goals.
|
111 |
+
- Briefly explain the product or service being promoted.
|
112 |
+
- Define your ideal customer with clear demographics, psychographics, and behavioral insights.
|
113 |
+
- Understand their needs, wants, motivations, and pain points.
|
114 |
+
- Clearly articulate the desired outcomes for the campaign.
|
115 |
+
- Use SMART goals (Specific, Measurable, Achievable, Relevant, and Time-bound) for clarity.
|
116 |
+
- Define key performance indicators (KPIs) to track progress and success.
|
117 |
+
- Specify the primary and secondary goals of the campaign.
|
118 |
+
- Examples include brand awareness, lead generation, sales growth, or website traffic.
|
119 |
+
- Clearly define what differentiates your product or service from competitors.
|
120 |
+
- Emphasize the value proposition and unique benefits offered to the target audience.
|
121 |
+
- Define the desired tone and personality of the campaign messaging.
|
122 |
+
- Identify the specific channels you will use to reach your target audience.
|
123 |
+
- Clearly state the desired action you want the audience to take.
|
124 |
+
- Make it specific, compelling, and easy to understand.
|
125 |
+
- Identify and analyze your key competitors in the market.
|
126 |
+
- Understand their strengths and weaknesses, target audience, and marketing strategies.
|
127 |
+
- Develop a differentiation strategy to stand out from the competition.
|
128 |
+
- Define how you will track the success of the campaign.
|
129 |
+
- Utilize relevant KPIs to measure performance and return on investment (ROI).
|
130 |
+
Give proper bullet points and headlines for the marketing campaign. Do not produce any empty lines.
|
131 |
+
Be very succinct and to the point.
|
132 |
+
"""
|
133 |
+
#----------------------------------------------------------
|
134 |
+
|
135 |
+
if st.button("Generate Campaign"):
|
136 |
+
# Assuming you have a function to generate marketing campaigns
|
137 |
+
campaign_details = gemini_pro_response(product_name + " " + target_audience + " " + " ".join(campaign_objective) + " " + str( ))
|
138 |
+
st.markdown(campaign_details)
|
139 |
+
|
140 |
+
|
141 |
+
|
142 |
+
# chatbot page
|
143 |
+
if selected == 'ChatBot':
|
144 |
+
model = load_gemini_pro_model()
|
145 |
+
|
146 |
+
# Initialize chat session in Streamlit if not already present
|
147 |
+
if "chat_session" not in st.session_state: # Renamed for clarity
|
148 |
+
st.session_state.chat_session = model.start_chat(history=[])
|
149 |
+
|
150 |
+
# Display the chatbot's title on the page
|
151 |
+
st.title("π€ ChatBot")
|
152 |
+
|
153 |
+
# Display the chat history
|
154 |
+
for message in st.session_state.chat_session.history:
|
155 |
+
with st.chat_message(translate_role_for_streamlit(message.role)):
|
156 |
+
st.markdown(message.parts[0].text)
|
157 |
+
|
158 |
+
# Input field for user's message
|
159 |
+
user_prompt = st.chat_input("Ask Gemini-Pro...") # Renamed for clarity
|
160 |
+
if user_prompt:
|
161 |
+
# Add user's message to chat and display it
|
162 |
+
st.chat_message("user").markdown(user_prompt)
|
163 |
+
|
164 |
+
# Send user's message to Gemini-Pro and get the response
|
165 |
+
gemini_response = st.session_state.chat_session.send_message(user_prompt) # Renamed for clarity
|
166 |
+
|
167 |
+
# Display Gemini-Pro's response
|
168 |
+
with st.chat_message("assistant"):
|
169 |
+
st.markdown(gemini_response.text)
|
170 |
+
|
171 |
+
|
172 |
+
# Image captioning page
|
173 |
+
if selected == "Image Captioning":
|
174 |
+
|
175 |
+
st.title("π· Snap Narrate")
|
176 |
+
|
177 |
+
uploaded_image = st.file_uploader("Upload an image...", type=["jpg", "jpeg", "png"])
|
178 |
+
|
179 |
+
if st.button("Generate Caption"):
|
180 |
+
image = Image.open(uploaded_image)
|
181 |
+
|
182 |
+
col1, col2 = st.columns(2)
|
183 |
+
|
184 |
+
with col1:
|
185 |
+
resized_img = image.resize((800, 500))
|
186 |
+
st.image(resized_img)
|
187 |
+
|
188 |
+
default_prompt = "write a short caption for this image" # change this prompt as per your requirement
|
189 |
+
|
190 |
+
# get the caption of the image from the gemini-pro-vision LLM
|
191 |
+
caption = gemini_pro_vision_response(default_prompt, image)
|
192 |
+
|
193 |
+
with col2:
|
194 |
+
st.info(caption)
|
195 |
+
|
196 |
+
|
197 |
+
# text embedding model
|
198 |
+
if selected == "Embed text":
|
199 |
+
|
200 |
+
st.title("π‘ Embed Text")
|
201 |
+
|
202 |
+
# text box to enter prompt
|
203 |
+
user_prompt = st.text_area(label='', placeholder="Enter the text to get embeddings")
|
204 |
+
|
205 |
+
if st.button("Get Response"):
|
206 |
+
response = embeddings_model_response(user_prompt)
|
207 |
+
st.markdown(response)
|
208 |
+
|
209 |
+
|
210 |
+
# text embedding model
|
211 |
+
if selected == "Ask me anything":
|
212 |
+
|
213 |
+
st.title("β Ask me a question")
|
214 |
+
|
215 |
+
# text box to enter prompt
|
216 |
+
user_prompt = st.text_area(label='', placeholder="Ask me anything...")
|
217 |
+
|
218 |
+
if st.button("Get Response"):
|
219 |
+
response = gemini_pro_response(user_prompt)
|
220 |
+
st.markdown(response)
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
google-generativeai==0.4.0
|
2 |
+
pillow==10.2.0
|
3 |
+
streamlit==1.31.1
|
4 |
+
streamlit-option-menu==0.3.12
|
test_image.png
ADDED
![]() |
Git LFS Details
|