Spaces:
Sleeping
Sleeping
SarowarSaurav
commited on
Commit
•
387af10
1
Parent(s):
eab11b1
Update app.py
Browse files
app.py
CHANGED
@@ -5,215 +5,43 @@ knowledge_base = {
|
|
5 |
"SOP": "Sales Operations Planning / Standard Operational Procedure / Start of Production",
|
6 |
"NTO": "Net Turnover",
|
7 |
"D&A": "Data & Analytics",
|
8 |
-
"HOF":
|
9 |
"APFO": "Adjusted Profit from Operations",
|
10 |
"LEP": "Limited Edition Pack",
|
11 |
"AD": "Area Director",
|
12 |
-
"IDT": "Information & Digital Technology",
|
13 |
-
"CORA": "Corporate & Regulatory Affairs",
|
14 |
-
"EOB": "End of Business Day",
|
15 |
-
"OOO":
|
16 |
}
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
21 |
return response
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
<
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
top: 50%;
|
45 |
-
left: 50%;
|
46 |
-
transform: translate(-50%, -50%);
|
47 |
-
width: 300px;
|
48 |
-
height: 80vh;
|
49 |
-
max-height: 500px;
|
50 |
-
border-radius: 15px;
|
51 |
-
background-color: rgba(0, 0, 0, .5);
|
52 |
-
overflow: hidden;
|
53 |
-
}
|
54 |
-
.chat-title {
|
55 |
-
background-color: rgba(0, 0, 0, .3);
|
56 |
-
width: 100%;
|
57 |
-
height: 50px;
|
58 |
-
display: flex;
|
59 |
-
align-items: center;
|
60 |
-
padding: 0 10px;
|
61 |
-
box-sizing: border-box;
|
62 |
-
}
|
63 |
-
.chat-title h2 {
|
64 |
-
margin: 0;
|
65 |
-
color: #f0f0f0;
|
66 |
-
font-size: 16px;
|
67 |
-
flex-grow: 1;
|
68 |
-
}
|
69 |
-
.chat-title .avatar {
|
70 |
-
width: 30px;
|
71 |
-
height: 30px;
|
72 |
-
border-radius: 50%;
|
73 |
-
overflow: hidden;
|
74 |
-
margin-right: 10px;
|
75 |
-
}
|
76 |
-
.chat-title .avatar img {
|
77 |
-
width: 100%;
|
78 |
-
height: 100%;
|
79 |
-
border-radius: 50%;
|
80 |
-
}
|
81 |
-
.messages {
|
82 |
-
width: 100%;
|
83 |
-
height: calc(100% - 90px);
|
84 |
-
overflow-y: auto;
|
85 |
-
padding: 10px;
|
86 |
-
box-sizing: border-box;
|
87 |
-
}
|
88 |
-
.messages .message {
|
89 |
-
max-width: calc(100% - 76px);
|
90 |
-
padding: 8px;
|
91 |
-
margin: 8px 0;
|
92 |
-
border-radius: 5px;
|
93 |
-
background-color: rgba(255, 255, 255, .1);
|
94 |
-
color: #e3e3e3;
|
95 |
-
font-size: 13px;
|
96 |
-
position: relative;
|
97 |
-
word-break: break-all;
|
98 |
-
}
|
99 |
-
.messages .message.personal {
|
100 |
-
background-color: rgba(76, 175, 80, .1);
|
101 |
-
margin-left: auto;
|
102 |
-
}
|
103 |
-
.messages .timestamp {
|
104 |
-
position: absolute;
|
105 |
-
right: -50px;
|
106 |
-
bottom: 0;
|
107 |
-
font-size: 12px;
|
108 |
-
color: #bababa;
|
109 |
-
}
|
110 |
-
.action-box {
|
111 |
-
background-color: rgba(0, 0, 0, .3);
|
112 |
-
width: 100%;
|
113 |
-
height: 40px;
|
114 |
-
display: flex;
|
115 |
-
align-items: center;
|
116 |
-
box-sizing: border-box;
|
117 |
-
}
|
118 |
-
.action-box-input {
|
119 |
-
flex-grow: 1;
|
120 |
-
background-color: transparent;
|
121 |
-
border: 0;
|
122 |
-
padding: 0 10px;
|
123 |
-
color: white;
|
124 |
-
font-size: 16px;
|
125 |
-
height: 100%;
|
126 |
-
}
|
127 |
-
.action-box-input:focus {
|
128 |
-
outline: none;
|
129 |
-
}
|
130 |
-
.action-box-submit {
|
131 |
-
width: 60px;
|
132 |
-
height: 100%;
|
133 |
-
background-color: rgba(189, 195, 199, .2);
|
134 |
-
color: white;
|
135 |
-
border: 0;
|
136 |
-
cursor: pointer;
|
137 |
-
display: flex;
|
138 |
-
align-items: center;
|
139 |
-
justify-content: center;
|
140 |
-
}
|
141 |
-
.action-box-submit i {
|
142 |
-
font-size: 16px;
|
143 |
-
}
|
144 |
-
</style>
|
145 |
-
</head>
|
146 |
-
<body>
|
147 |
-
<div class="chat">
|
148 |
-
<div class="chat-title">
|
149 |
-
<div class="avatar">
|
150 |
-
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/764024/profile/profile-512.jpg" alt="Avatar">
|
151 |
-
</div>
|
152 |
-
<h2>Kelly Chen</h2>
|
153 |
-
</div>
|
154 |
-
<div class="messages">
|
155 |
-
<div class="messages-content"></div>
|
156 |
-
</div>
|
157 |
-
<div class="action-box">
|
158 |
-
<textarea class="action-box-input" type="text" placeholder="Type message..."></textarea>
|
159 |
-
<button class="action-box-submit" type="submit">
|
160 |
-
<i class="fa fa-paper-plane"></i>
|
161 |
-
</button>
|
162 |
-
</div>
|
163 |
-
</div>
|
164 |
-
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
165 |
-
<script>
|
166 |
-
var messages = $(".messages-content");
|
167 |
-
|
168 |
-
function insertMessage() {
|
169 |
-
var msgText = $(".action-box-input").val();
|
170 |
-
if ($.trim(msgText) == "") {
|
171 |
-
return false;
|
172 |
-
}
|
173 |
-
var msg = $("<div>").addClass("message personal").text(msgText);
|
174 |
-
$("<div>").addClass("timestamp").text(getTimestamp()).appendTo(msg);
|
175 |
-
msg.appendTo($('.messages-content'));
|
176 |
-
$(".action-box-input").val(null);
|
177 |
-
|
178 |
-
gradioApp().get_abbreviation(msgText).then(function(response) {
|
179 |
-
var responseMsg = $("<div>").addClass("message").text(response);
|
180 |
-
$("<div>").addClass("timestamp").text(getTimestamp()).appendTo(responseMsg);
|
181 |
-
responseMsg.appendTo($('.messages-content'));
|
182 |
-
updateScrollbar();
|
183 |
-
});
|
184 |
-
}
|
185 |
-
|
186 |
-
function updateScrollbar() {
|
187 |
-
messages.scrollTop(messages[0].scrollHeight);
|
188 |
-
}
|
189 |
-
|
190 |
-
function getTimestamp() {
|
191 |
-
var d = new Date();
|
192 |
-
return d.getHours() + ":" + (d.getMinutes() < 10 ? '0' : '') + d.getMinutes();
|
193 |
-
}
|
194 |
-
|
195 |
-
$(window).on('keydown', function (e) {
|
196 |
-
if (e.which == 13) {
|
197 |
-
insertMessage();
|
198 |
-
return false;
|
199 |
-
}
|
200 |
-
});
|
201 |
-
|
202 |
-
$(document).ready(function() {
|
203 |
-
messages.scrollTop(messages[0].scrollHeight);
|
204 |
-
});
|
205 |
-
</script>
|
206 |
-
</body>
|
207 |
-
</html>
|
208 |
-
''')
|
209 |
-
|
210 |
-
chatbot_interface = gr.Interface(
|
211 |
-
fn=get_abbreviation,
|
212 |
-
inputs="text",
|
213 |
-
outputs="text",
|
214 |
-
live=True
|
215 |
-
)
|
216 |
-
chatbot_interface.launch()
|
217 |
-
|
218 |
-
if __name__ == "__main__":
|
219 |
-
demo.launch()
|
|
|
5 |
"SOP": "Sales Operations Planning / Standard Operational Procedure / Start of Production",
|
6 |
"NTO": "Net Turnover",
|
7 |
"D&A": "Data & Analytics",
|
8 |
+
"HOF":"Head of Function",
|
9 |
"APFO": "Adjusted Profit from Operations",
|
10 |
"LEP": "Limited Edition Pack",
|
11 |
"AD": "Area Director",
|
12 |
+
"IDT" : "Information & Digital Technology",
|
13 |
+
"CORA" : "Corporate & Regulatory Affairs",
|
14 |
+
"EOB" : "End of Business Day",
|
15 |
+
"OOO" :"Out of Office",
|
16 |
}
|
17 |
|
18 |
+
# Define the Gradio interface function
|
19 |
+
def chatbot_interface(acronym):
|
20 |
+
acronym = acronym.strip().toUpperCase() # Remove leading/trailing whitespace and convert to uppercase
|
21 |
+
if (acronym in knowledge_base):
|
22 |
+
response = f"Answer: {knowledge_base[acronym]}"
|
23 |
+
else:
|
24 |
+
response = "Not found in the BATCCAPEDIA"
|
25 |
return response
|
26 |
|
27 |
+
# HTML code to add the logo
|
28 |
+
header_html = """
|
29 |
+
<div style="text-align: center; margin-bottom: 20px;">
|
30 |
+
<img src="https://www.batbangladesh.com/imgs/BAT_Bangladesh_Logo.png" alt="BAT Bangladesh Logo" style="max-width: 200px;">
|
31 |
+
</div>
|
32 |
+
"""
|
33 |
+
|
34 |
+
# Create the Gradio interface
|
35 |
+
iface = gr.Interface(
|
36 |
+
fn=chatbot_interface,
|
37 |
+
inputs="text",
|
38 |
+
outputs="text",
|
39 |
+
css="footer{display:none !important}",
|
40 |
+
title="BATB Acronym Finder",
|
41 |
+
description="Dictionary of Abbreviations & Acronyms",
|
42 |
+
theme='default',
|
43 |
+
header_html=header_html
|
44 |
+
)
|
45 |
+
|
46 |
+
# Launch the interface
|
47 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|