import base64 import streamlit as st from transformers import pipeline # Set page configuration st.set_page_config( page_title="DLA GPT", page_icon=":robot:", layout="wide", initial_sidebar_state="collapsed", ) # Custom CSS to change the background color and add a logo st.markdown( """ """, unsafe_allow_html=True, ) def get_image_base64(image_path): with open(image_path, "rb") as img_file: return base64.b64encode(img_file.read()).decode() image_base64 = get_image_base64("./DLA.png") # Add logo at the top st.markdown( f"""
Logo
DLA GPT
""", unsafe_allow_html=True, ) # Chatbot interaction logic if "messages" not in st.session_state: st.session_state.messages = [] def get_bot_response(prompt): pipe = pipeline("text-generation", model="gpt2") output = pipe(prompt, max_length=100) return output[0]['generated_text'] def display_history(): # Chat interface st.markdown("
Here is the answer", unsafe_allow_html=True) for message in st.session_state.messages[:10]: st.markdown(f"
You: {message[0]}
Bot: {message[1]}
", unsafe_allow_html=True) st.markdown("
", unsafe_allow_html=True) def main(): user_input = st.text_input(" ", "") if user_input: bot_response = get_bot_response(user_input) message_pair = (user_input, bot_response) st.session_state.messages.insert(0, message_pair) display_history() if __name__ == '__main__': main()