from datetime import datetime import streamlit as st import os from openai import OpenAI class ChatBot: def __init__(self): self.client = OpenAI(api_key=os.environ["OPENAI_API_KEY"]) self.history = [{"role": "system", "content": "You are a helpful assistant."}] def generate_response(self, prompt: str) -> str: self.history.append({"role": "user", "content": prompt}) completion = self.client.chat.completions.create( model="gpt-4o", messages=self.history ) response = completion.choices[0].message.content self.history.append({"role": "assistant", "content": response}) return response def get_history(self) -> list: return self.history # Read the content of the Markdown file def read_markdown_file(file_path): with open(file_path, 'r', encoding='utf-8') as file: return file.read() # Credit: Time def current_year(): now = datetime.now() return now.year st.set_page_config(layout="wide") st.title("Yin's Profile 🤖") with st.sidebar: with st.expander("Instruction Manual"): st.markdown(""" ## Yin's Profile 🤖 Chatbot This Streamlit app allows you to chat with GPT-4o model. ### How to Use: 1. **Input**: Type your prompt into the chat input box labeled "What is up?". 2. **Response**: The app will display a response from GPT-4o. 3. **Chat History**: Previous conversations will be shown on the app. ### Credits: - **Developer**: [Yiqiao Yin](https://www.y-yin.io/) | [App URL](https://huggingface.co/spaces/eagle0504/gpt-4o-demo) | [LinkedIn](https://www.linkedin.com/in/yiqiaoyin/) | [YouTube](https://youtube.com/YiqiaoYin/) Enjoy chatting with Yin's assistant! """) # Example: st.success("Example: Who is Yiqiao Yin?") st.success("Example: What did Yiqiao do at graduate school?") st.success("Example: Where to find published papers by Yiqiao?") st.success("Example: What is Yiqiao's view on AI?") st.success("Example: What are some online links by Yiqiao I can read about?") st.success("Example: What is Yiqiao's view on stock market?") # Credit: current_year = current_year() # This will print the current year st.markdown( f"""