File size: 3,063 Bytes
2f68ed7
 
5c48b46
 
2f68ed7
 
 
0f00e7f
2f68ed7
0f00e7f
2f68ed7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0f00e7f
 
 
 
 
 
 
 
 
2f68ed7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5c48b46
f1beaad
5c48b46
264d982
5c48b46
 
2f68ed7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
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(
    """
    <style>
    .stApp {
        background-color: black;
        color: white;
    }
    .logo-container {
        margin-bottom: 20px;
    }
    .chat-container {
        border-radius: 10px;
        padding: 5px;
        margin-top: 20px;
        width: 100%;
    }
    .qa-container {
        border-top: 1px dashed silver;
        border-bottom: 1px dashed silver;
        padding: 10px;
        margin-top: 20px;
        width: 100%;
    }
    .message {
        margin-bottom: 15px;
        padding: 10px;
        border-radius: 5px;
    }
    .user-message {
        background-color: #373749;
        color: silver;
    }
    .bot-message {
        background-color: #333333;
        color: silver;
    }
    div[data-baseweb="input"] > div {
        width: 100% !important;  /* Make the input box take full width */
    }
    input[type="text"] {
        height: auto;
        padding: 10px;
        white-space: normal;
        overflow-wrap: break-word;
    }
    </style>
    """,
    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"""
    <div class="logo-container">
        <div style = "text-align:left; border: width: 15%; float:left"><img src="data:image/png;base64,{image_base64}" alt="Logo" style="width:80px;"></div>
        <div style = "color:#FFD700; text-shadow: 5px 5px #99ccff; font-family:Cursive; font-size:48px; font-weight:bold; text-align:center; width: 80%; float:left">DLA GPT</div>
    </div>
    """,
    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("<div class='chat-container' style = 'color: #9999b2; font-weight:bold; font-style: italic;'>Here is the answer", unsafe_allow_html=True)

    for message in st.session_state.messages[:10]:
        st.markdown(f"<div class = 'qa-container'><div class='message user-message'><b>You</b>: {message[0]}</div><div class='message bot-message'><b>Bot</b>: {message[1]}</div></div>", unsafe_allow_html=True)

    st.markdown("</div>", 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()