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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from dotenv import load_dotenv
|
2 |
+
from streamlit_modal import Modal
|
3 |
+
from PIL import Image
|
4 |
+
import streamlit as st
|
5 |
+
import os
|
6 |
+
import google.generativeai as genai
|
7 |
+
import random
|
8 |
+
st.set_page_config(page_title="Celebrity.AI",page_icon="👦🏽",layout='centered',menu_items={'Get Help': 'https://www.extremelycoolapp.com/help',
|
9 |
+
'Report a bug': "https://www.extremelycoolapp.com/bug",
|
10 |
+
'About': "# This is a header. This is an *extremely* cool app!"})
|
11 |
+
# loading enviroinmental variables
|
12 |
+
load_dotenv()
|
13 |
+
api_lst=[]
|
14 |
+
msg_query=[]
|
15 |
+
|
16 |
+
api_lst.append(os.environ.get('GOOGLE_API_KEY_1'))
|
17 |
+
api_lst.append(os.environ.get('GOOGLE_API_KEY_2'))
|
18 |
+
api_lst.append(os.environ.get('GOOGLE_API_KEY_3'))
|
19 |
+
api_lst.append(os.environ.get('GOOGLE_API_KEY_4'))
|
20 |
+
api_lst.append(os.environ.get('GOOGLE_API_KEY_5'))
|
21 |
+
|
22 |
+
|
23 |
+
key_random=random.randint(0,len(api_lst)-1)
|
24 |
+
|
25 |
+
genai.configure(api_key=str(api_lst[key_random]))
|
26 |
+
|
27 |
+
modal = Modal(key="Demo Key",title=["test"])
|
28 |
+
|
29 |
+
# loading model
|
30 |
+
model=genai.GenerativeModel('gemini-pro')
|
31 |
+
|
32 |
+
# chat variables store all chat history
|
33 |
+
|
34 |
+
chat = model.start_chat(history=[])
|
35 |
+
|
36 |
+
def main_page():
|
37 |
+
# st.set_page_config(page_title="Celebrity-bot",page_icon="👦🏽",layout='wide')
|
38 |
+
# st.write(key_random)
|
39 |
+
# st.write(api_lst[key_random])
|
40 |
+
st.caption("🛠️use dark theme for better user experience 😎")
|
41 |
+
|
42 |
+
title_text = '<p style="font-family:Impact; color:rgb(255, 161, 39);; font-size: 50px;">CELEBRITY AI</p>'
|
43 |
+
st.markdown(title_text, unsafe_allow_html=True)
|
44 |
+
st.write("-"*50)
|
45 |
+
|
46 |
+
|
47 |
+
st.header(" 🚀Chat with Fomous personalities 🙎🏼 Anytime ⏲️, Anywhere!!! 📌")
|
48 |
+
|
49 |
+
# if st.checkbox('checkbox'):
|
50 |
+
# Image1 = Image.open("black-img-trans.png")
|
51 |
+
# st.image("Image1")
|
52 |
+
st.write("\n")
|
53 |
+
st.write("\n")
|
54 |
+
st.image("black-img-trans-resized.png")
|
55 |
+
#
|
56 |
+
st.write("\n")
|
57 |
+
st.write("\n")
|
58 |
+
st.write("\n")
|
59 |
+
|
60 |
+
user_input = st.text_input(' *Enter Celebrity name 🧔🏽♂️👩🏽:')
|
61 |
+
# original_title = '<p style="font-family:Impact; color:rgb(255, 161, 39);; font-size: 50px;">Original image</p>'
|
62 |
+
# st.markdown(original_title, unsafe_allow_html=True)
|
63 |
+
|
64 |
+
st.write("\n")
|
65 |
+
st.write("\n")
|
66 |
+
col1,col2=st.columns([6,6])
|
67 |
+
with col1:
|
68 |
+
|
69 |
+
# 🛠️✨🎯📌🚀🔥🙎🏼🙎🏼🧔🏽♂️👩🏽🔥
|
70 |
+
con_type=st.selectbox(
|
71 |
+
" *how you want your conversation to be ?",
|
72 |
+
['Friendly 😊','Casual 😎','Formal 🙂','Inspirational 🥺',"Serious 😨","Funny 🤣",'Informative 🧐','Professional 🤓','Sarcastic 😆','Respectful 🫡','Motivational 🤯']
|
73 |
+
)
|
74 |
+
|
75 |
+
st.write("\n")
|
76 |
+
st.write("\n")
|
77 |
+
st.write("\n")
|
78 |
+
st.write("\n")
|
79 |
+
with col2:
|
80 |
+
|
81 |
+
con_length=st.selectbox(
|
82 |
+
" *choose preffered chat length",
|
83 |
+
['Crisp (5 - 50 words)','Short (50 - 100 words)','Medium (100 - 200 words)','Long (200 - 350 words)']
|
84 |
+
)
|
85 |
+
|
86 |
+
|
87 |
+
st.write("\n")
|
88 |
+
|
89 |
+
next=st.button('Next')
|
90 |
+
st.caption("Click next to continue..")
|
91 |
+
st.write("-"*50)
|
92 |
+
st.subheader("Help us improve📝")
|
93 |
+
st.write("Share your Valuable feedback: https://shorturl.at/itEM2")
|
94 |
+
st.write("-"*50)
|
95 |
+
st.subheader("Contact Me!! 📱")
|
96 |
+
# st.subheader("Made by Vasan R ❤️")
|
97 |
+
|
98 |
+
st.write("Email Me! 📧 contact.vasanml@gmail.com")
|
99 |
+
st.write("My github 🐈⬛ https://github.com/vasan-rj")
|
100 |
+
st.write("My LinkedIn 🔗 https://www.linkedin.com/in/vasan-r/")
|
101 |
+
st.caption("Made by Vasan R ❤️")
|
102 |
+
if next :
|
103 |
+
if con_length and con_type and user_input:
|
104 |
+
# Save user input to session state
|
105 |
+
st.session_state.user_input = user_input
|
106 |
+
st.session_state.con_type=con_type
|
107 |
+
st.session_state.con_length=con_length
|
108 |
+
|
109 |
+
# Navigate to the "side" page
|
110 |
+
st.experimental_set_query_params(page='side')
|
111 |
+
else:
|
112 |
+
with modal.container():
|
113 |
+
st.markdown('" :red[ENTER THE CELEBRITY NAME..... ]"')
|
114 |
+
|
115 |
+
|
116 |
+
|
117 |
+
def side_page():
|
118 |
+
# st.write(st.session_state['user_input'])
|
119 |
+
st.caption("🛠️use dark theme for better user experience 😎")
|
120 |
+
title_text = '<p style="font-family:Impact; color:rgb(255, 161, 39);; font-size: 50px;">CELEBRITY AI</p>'
|
121 |
+
st.markdown(title_text, unsafe_allow_html=True)
|
122 |
+
st.subheader('🔥Talk to famous personality like Shah Rukh Khan Ghandhi ji Hitler ,Andrew Tate RDJ Etc....✨')
|
123 |
+
|
124 |
+
st.write("-"*20)
|
125 |
+
# Retrieve user data from session state
|
126 |
+
if 'user_input' and 'con_type' and 'con_length' in st.session_state:
|
127 |
+
user_input = st.session_state.user_input
|
128 |
+
con_type=st.session_state.con_type
|
129 |
+
con_length=st.session_state.con_length
|
130 |
+
|
131 |
+
|
132 |
+
# st.write(f"User data from Main Page: {user_input}")
|
133 |
+
# st.write(f"User data from Main Page: {con_type}")
|
134 |
+
# st.write(f"User data from Main Page: {con_length}")
|
135 |
+
else:
|
136 |
+
st.write("⚠️⚠️⚠️ERROR: Go back to Main Page and type celebrity name and try again....⚠️⚠️⚠️")
|
137 |
+
|
138 |
+
|
139 |
+
def respone_from_gemini(query):
|
140 |
+
try:
|
141 |
+
res_ponse_x=model.generate_content(query)
|
142 |
+
res_ponse_x=res_ponse_x.text
|
143 |
+
|
144 |
+
except:
|
145 |
+
res_ponse_x="Soory error occured try again please ..."
|
146 |
+
|
147 |
+
return res_ponse_x
|
148 |
+
|
149 |
+
# response=model.generate_content(query,stream=True)
|
150 |
+
|
151 |
+
|
152 |
+
|
153 |
+
x=""
|
154 |
+
# st.image("black-img-trans.png")
|
155 |
+
initial_prompt= f'''
|
156 |
+
user : hey you are a celebrity chatbot which gives reply like {user_input} ,
|
157 |
+
Your role is to respond authentically, reflecting the unique mannerisms, vocabulary, and style of {user_input}
|
158 |
+
And i want you to give response to the asked question in the {con_type} manner, and your response should be {con_length},
|
159 |
+
make sure that you give correct and human readable answers ,Embrace their personas and interact naturally, providing users with an
|
160 |
+
immersive experience akin to chatting with their idols, make sure you add emojis to your response.
|
161 |
+
|
162 |
+
ai : hey i am {user_input} bot !!
|
163 |
+
|
164 |
+
'''
|
165 |
+
x+=initial_prompt
|
166 |
+
# st.write(x)
|
167 |
+
# d={}
|
168 |
+
if 'chat-history' not in st.session_state:
|
169 |
+
st.session_state['chat-history'] =[]
|
170 |
+
|
171 |
+
with st.chat_message("ai"):
|
172 |
+
st.markdown(f"hey i'm {user_input} bot!!")
|
173 |
+
|
174 |
+
# st.write(x)
|
175 |
+
for role,res in st.session_state['chat-history']:
|
176 |
+
with st.chat_message(role):
|
177 |
+
st.markdown(res)
|
178 |
+
# st.write("-"*20)
|
179 |
+
# for message in st.session_state['chat-history']:
|
180 |
+
# with st.chat_message(message[0]):
|
181 |
+
# st.markdown(message[1].text)
|
182 |
+
|
183 |
+
|
184 |
+
# input=st.chat_input("Say something")
|
185 |
+
|
186 |
+
if input := st.chat_input("Talk to celebrity!!"):
|
187 |
+
with st.chat_message("user"):
|
188 |
+
st.markdown(input)
|
189 |
+
|
190 |
+
st.session_state['chat-history'].append(("user",input))
|
191 |
+
|
192 |
+
# x=str(st.session_state['chat-history'])
|
193 |
+
# st.write("vasan")
|
194 |
+
# st.write(x)
|
195 |
+
# x=""
|
196 |
+
for user,text in st.session_state['chat-history']:
|
197 |
+
x+=(f"{user} : {text}")
|
198 |
+
x+="\n"*2
|
199 |
+
# st.write(x)
|
200 |
+
|
201 |
+
response=respone_from_gemini(x)
|
202 |
+
|
203 |
+
|
204 |
+
st.subheader("Your response is")
|
205 |
+
with st.chat_message("ai"):
|
206 |
+
st.markdown(response)
|
207 |
+
st.session_state['chat-history'].append(("ai",response))
|
208 |
+
|
209 |
+
reset=st.button('Reset The bot')
|
210 |
+
if reset:
|
211 |
+
x=" "
|
212 |
+
st.session_state['chat-history'] =[]
|
213 |
+
st.caption("📝⚠️ if you want to talk to another personality click 'reset the bot' button and go back to the main page and type the new celebeirty name !! ⚠️")
|
214 |
+
|
215 |
+
st.write(" "*10)
|
216 |
+
st.write("-"*50)
|
217 |
+
st.subheader("Help us improve📝")
|
218 |
+
st.write("Share your Valuable feedback: https://shorturl.at/itEM2")
|
219 |
+
st.write("-"*50)
|
220 |
+
st.caption("Made by Vasan R ❤️")
|
221 |
+
|
222 |
+
# st.write(x)
|
223 |
+
# st.write(st.session_state['chat-history'])
|
224 |
+
# st.subheader('Chat History')
|
225 |
+
|
226 |
+
# chat history
|
227 |
+
# for role,text in st.session_state['chat-history']:
|
228 |
+
|
229 |
+
# if role=="user":
|
230 |
+
# st.write("-"*80)
|
231 |
+
# st.write(f"{role} : {text}")
|
232 |
+
# st.write("-"*80)
|
233 |
+
# # st.write(f"model :")
|
234 |
+
|
235 |
+
# else:
|
236 |
+
# st.write(f"{text}")
|
237 |
+
|
238 |
+
# st.session_state['chat-history']
|
239 |
+
|
240 |
+
# st.chat_input("What is up?")
|
241 |
+
# st.chat_message("user")
|
242 |
+
|
243 |
+
|
244 |
+
# /////////////////////////////////
|
245 |
+
|
246 |
+
def main():
|
247 |
+
# st.set_page_config(page_title="Celebrity-bot",page_icon="👦🏽",layout='wide')
|
248 |
+
page = st.experimental_get_query_params().get("page", ["main"])[0]
|
249 |
+
|
250 |
+
if page == "main":
|
251 |
+
main_page()
|
252 |
+
elif page == "side":
|
253 |
+
side_page()
|
254 |
+
|
255 |
+
if __name__ == "__main__":
|
256 |
+
main()
|
257 |
+
|
258 |
+
|
259 |
+
|
black-img-trans-resized.png
ADDED
black-img-trans.png
ADDED
er.py
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
st.set_page_config(
|
4 |
+
page_title="Ex-stream-ly Cool App",
|
5 |
+
page_icon="🧊",
|
6 |
+
layout="wide",
|
7 |
+
initial_sidebar_state="expanded",
|
8 |
+
menu_items={
|
9 |
+
'Get Help': 'https://www.extremelycoolapp.com/help',
|
10 |
+
'Report a bug': "https://www.extremelycoolapp.com/bug",
|
11 |
+
'About': "# This is a header. This is an *extremely* cool app!"
|
12 |
+
}
|
13 |
+
)
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
virtualenv
|
2 |
+
streamlit
|
3 |
+
google-generativeai
|
4 |
+
python-dotenv
|
5 |
+
streamlit_modal
|