izzygamesandappsofficial/Testonly
0
1import streamlit as st2import os, json, uuid, time3from groq import Groq4 5st.set_page_config(6 page_title="Izzy AI",7 layout="wide"8)9 10DATA_DIR = "data"11CHAT_FILE = f"{DATA_DIR}/chats.json"12os.makedirs(DATA_DIR, exist_ok=True)13 14if not os.path.exists(CHAT_FILE):15 with open(CHAT_FILE, "w") as f:16 json.dump({}, f)17 18client = Groq(api_key=os.environ.get("GROQ_API_KEY"))19 20def load_chats():21 with open(CHAT_FILE, "r") as f:22 return json.load(f)23 24def save_chats(chats):25 with open(CHAT_FILE, "w") as f:26 json.dump(chats, f, indent=2)27 28ss = st.session_state29 30if "chat_id" not in ss:31 ss.chat_id = None32 33if "anim_text_index" not in ss:34 ss.anim_text_index = 035 ss.anim_char_index = 036 ss.anim_phase = "typing" 37 ss.anim_time = time.time()38 39chats = load_chats()40 41if not chats:42 cid = str(uuid.uuid4())43 chats[cid] = {"title": "Chat 1", "messages": []}44 save_chats(chats)45 ss.chat_id = cid46 47if ss.chat_id not in chats:48 ss.chat_id = list(chats.keys())[0]49 50active_chat = chats[ss.chat_id]51 52with st.sidebar:53 st.markdown("## ๐ฌ Izzy AI")54 55 if st.button("โ New Chat", use_container_width=True):56 cid = str(uuid.uuid4())57 chats[cid] = {"title": f"Chat {len(chats)+1}", "messages": []}58 save_chats(chats)59 ss.chat_id = cid60 ss.anim_text_index = 061 ss.anim_char_index = 062 ss.anim_phase = "typing"63 ss.anim_time = time.time()64 st.rerun()65 66 for cid, chat in chats.items():67 if st.button(chat["title"], key=cid, use_container_width=True):68 ss.chat_id = cid69 st.rerun()70 71st.markdown("""72<style>73body {74 background: #ffffff;75}76.welcome-container {77 display: flex;78 justify-content: center;79 align-items: center;80 margin-top: 20vh;81 padding: 0 20px;82 text-align: center;83}84.welcome {85 font-weight: 700;86 background: linear-gradient(90deg, #1a73e8, #7b61ff);87 -webkit-background-clip: text;88 -webkit-text-fill-color: transparent;89 display: inline-block;90 font-family: 'Inter', sans-serif;91 line-height: 1.2;92}93.cursor {94 display: inline-block;95 background-color: #1a73e8;96 margin-left: 5px;97 animation: blink 0.7s step-end infinite;98}99@keyframes blink {100 from, to { background-color: transparent; }101 50% { background-color: #1a73e8; }102}103.chat-wrap {104 max-width: 850px;105 margin: auto;106 padding: 10px;107}108 109@media (min-width: 1024px) {110 .welcome { font-size: 50px; }111 .cursor { width: 4px; height: 50px; }112}113@media (min-width: 768px) and (max-width: 1023px) {114 .welcome { font-size: 40px; }115 .cursor { width: 3px; height: 40px; }116}117@media (max-width: 767px) {118 .welcome { font-size: 28px; }119 .cursor { width: 2px; height: 28px; }120 .welcome-container { margin-top: 15vh; }121}122</style>123""", unsafe_allow_html=True)124 125st.markdown('<div class="chat-wrap">', unsafe_allow_html=True)126 127for msg in active_chat["messages"]:128 with st.chat_message(msg["role"]):129 st.markdown(msg["content"])130 131st.markdown('</div>', unsafe_allow_html=True)132 133user_input = st.chat_input("Message Izzy AI...")134 135welcome_texts = [136 "Let's chat!",137 "I'm ready to assist",138 "How can I help you?",139 "Ready to answer"140]141 142if not active_chat["messages"] and not user_input:143 now = time.time()144 current_text = welcome_texts[ss.anim_text_index]145 146 if ss.anim_phase == "typing" and now - ss.anim_time > 0.07:147 ss.anim_char_index += 1148 ss.anim_time = now149 if ss.anim_char_index >= len(current_text):150 ss.anim_phase = "pause"151 ss.anim_time = now152 elif ss.anim_phase == "pause" and now - ss.anim_time > 2.0:153 ss.anim_phase = "deleting"154 ss.anim_time = now155 elif ss.anim_phase == "deleting" and now - ss.anim_time > 0.04:156 ss.anim_char_index -= 1157 ss.anim_time = now158 if ss.anim_char_index <= 0:159 ss.anim_phase = "typing"160 ss.anim_text_index = (ss.anim_text_index + 1) % len(welcome_texts)161 162 st.markdown(163 f"""164 <div class='welcome-container'>165 <div class='welcome'>{current_text[:ss.anim_char_index]}</div>166 <div class='cursor'></div>167 </div>168 """,169 unsafe_allow_html=True170 )171 time.sleep(0.02)172 st.rerun()173 174if user_input:175 active_chat["messages"].append({"role": "user", "content": user_input})176 if len(active_chat["messages"]) == 1:177 active_chat["title"] = user_input[:20]178 save_chats(chats)179 180 with st.chat_message("assistant"):181 response = client.chat.completions.create(182 model="llama-3.3-70b-versatile",183 messages=[{"role": "system", "content": "You are Izzy AI. Be accurate, concise, and professional."}] + active_chat["messages"]184 )185 reply = response.choices[0].message.content186 st.markdown(reply)187 188 active_chat["messages"].append({"role": "assistant", "content": reply})189 save_chats(chats)190 st.rerun()191 