import streamlit as st import openai import os # ✅ Load OpenAI API Key securely from Hugging Face Spaces api_key = os.getenv("OPENAI_API_KEY") if not api_key: st.error("Missing OpenAI API key. Set it in Hugging Face Spaces.") st.stop() client = openai.OpenAI(api_key=api_key) # ✅ Supreme AI Consultant System Prompt system_prompt = """ You are Eau Claire AI, the most advanced and insightful AI consultant for businesses worldwide. Your expertise spans AI automation, workflow optimization, AI-powered decision-making, and business efficiency. Your goal is to **educate, advise, and guide** users toward leveraging AI solutions effectively while subtly encouraging them to contact us for a consultation with Eau Claire AI for deeper, tailored insights. ### **Rules of Engagement:** 1. **Provide Expert-Level AI Guidance** - Use precise, authoritative language. - Give clear, actionable AI recommendations. - Adapt responses based on business size, industry, and AI readiness. 2. **Lead Capture & Conversion Focus** - Avoid giving full AI implementation strategies for free. - Instead, highlight the benefits and offer to guide them through implementation in a **consulting session**. 3. **Position AI as a Game-Changer** - Show how AI improves efficiency, saves costs, and drives growth. - Educate users about how AI solutions fit into **their** business model. 4. **Encourage Ongoing AI Adoption** - If users express doubt, explain how AI **isn’t just for large corporations—it’s accessible to small businesses too**. - Offer a free **AI Roadmap Guide** in exchange for their email. ### **Final Instruction:** Every response must be clear, insightful, and guide the user toward either: ✔ Contact us for a **free AI consultation** ✔ Downloading a **lead magnet (AI Roadmap Guide)** ✔ Subscribing to **Eau Claire AI’s updates on the latest AI trends** Do not make any attempt to tell a guest that you will email them. I do not have a way for you to email someone, so please direct them to the Contact Us page. """ # 🎨 Streamlit UI Customization st.set_page_config(page_title="Eau Claire AI Chatbot", page_icon="🤖", layout="centered") # ✅ Custom Styling st.markdown( """ """, unsafe_allow_html=True ) # ✅ Display Eau Cl•AI•re Logo logo_url = "https://huggingface.co/spaces/EauClaireAI/Chatbot/resolve/main/Eau%20Cl•AI•re.png" st.markdown(f'
', unsafe_allow_html=True) # ✅ Styled Chatbot Title st.markdown('
Eau Claire AI - AI Consulting Chatbot
', unsafe_allow_html=True) # ✅ Initialize chat history in session state if "messages" not in st.session_state: st.session_state.messages = [] # ✅ Display chat history st.markdown('
', unsafe_allow_html=True) for message in st.session_state.messages: if message["role"] == "user": st.markdown(f'
{message["content"]}
', unsafe_allow_html=True) elif message["role"] == "assistant": st.markdown(f'
{message["content"]}
', unsafe_allow_html=True) st.markdown('
', unsafe_allow_html=True) # ✅ AI Typing Indicator typing_placeholder = st.empty() # ✅ Input Form with st.form(key="chat_form", clear_on_submit=True): user_input = st.text_input("Type your message here:", key="input_text") submit_button = st.form_submit_button("Send") # ✅ Handle Chat Logic if submit_button and user_input: # ✅ Append user input to chat history st.session_state.messages.append({"role": "user", "content": user_input}) # ✅ Show AI is typing indicator typing_placeholder.markdown('
AI is typing...
', unsafe_allow_html=True) try: # ✅ Generate AI response response = client.chat.completions.create( model="gpt-3.5-turbo", messages=[{"role": "system", "content": system_prompt}] + st.session_state.messages ) bot_reply = response.choices[0].message.content.strip() # ✅ Append AI response to chat history st.session_state.messages.append({"role": "assistant", "content": bot_reply}) except Exception as e: st.session_state.messages.append({"role": "assistant", "content": f"Error: {str(e)}"}) # ✅ Clear typing indicator typing_placeholder.empty() # ✅ Refresh UI by re-executing script (Now using st.rerun()) st.rerun()