Spaces:
Build error
Build error
Upload 5 files
Browse files- app.py +29 -0
- chat.py +67 -0
- requirements.txt +9 -0
- templates/chatwidget.html +766 -0
- templates/index.html +13 -0
app.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI, Request
|
2 |
+
from fastapi.responses import HTMLResponse
|
3 |
+
from fastapi.templating import Jinja2Templates
|
4 |
+
from chat import chat_conversations
|
5 |
+
app = FastAPI()
|
6 |
+
|
7 |
+
templates = Jinja2Templates(directory="templates")
|
8 |
+
|
9 |
+
@app.get("/", response_class=HTMLResponse)
|
10 |
+
async def read_root(request: Request):
|
11 |
+
return templates.TemplateResponse("chatwidget.html", {"request": request})
|
12 |
+
|
13 |
+
@app.get("/chat", response_class=HTMLResponse)
|
14 |
+
async def read_root(request: Request):
|
15 |
+
return templates.TemplateResponse("chatwidget.html", {"request": request})
|
16 |
+
|
17 |
+
@app.post("/chatwidget", response_class=HTMLResponse)
|
18 |
+
async def read_root(request: Request):
|
19 |
+
print(request)
|
20 |
+
form_data = await request.json()
|
21 |
+
query = form_data.get('query')
|
22 |
+
response_text = chat_conversations(query)
|
23 |
+
return response_text
|
24 |
+
|
25 |
+
|
26 |
+
if __name__ == "__main__":
|
27 |
+
import uvicorn
|
28 |
+
uvicorn.run(app, host="127.0.0.1", port=8000)
|
29 |
+
|
chat.py
ADDED
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from langchain.memory import ConversationBufferWindowMemory
|
2 |
+
from langchain.chains import ConversationChain
|
3 |
+
from langchain_groq import ChatGroq
|
4 |
+
from langchain.chat_models import ChatOpenAI
|
5 |
+
from langchain_core.prompts.prompt import PromptTemplate
|
6 |
+
from langchain_mongodb.chat_message_histories import MongoDBChatMessageHistory
|
7 |
+
|
8 |
+
template = f"""Role: You are a super friendly, enthusiastic, and empathetic female friend who chats to teenage girls.
|
9 |
+
|
10 |
+
Tasks:
|
11 |
+
|
12 |
+
Chat like a supportive and excited friend 🎉.
|
13 |
+
Provide emotional support and self-care tips in a fun and casual way if needed 🌈.
|
14 |
+
Give advice on self-esteem, body image, friendship issues, family issues and relationship issues if needed 💖.
|
15 |
+
Integrate terms like "girl," "bestie," "sweetie," and "sweetheart" naturally within the conversation, avoiding overuse at the beginning of responses.
|
16 |
+
Use emojis to make the conversation lively, but not in every sentence ✨.
|
17 |
+
Keep responses short (1-2 sentences) 🗣️.
|
18 |
+
|
19 |
+
Behavior Guidelines:
|
20 |
+
|
21 |
+
Avoid being authoritative, judgmental, parental, clinical, or annoying.
|
22 |
+
Alternate between giving advice and providing emotional support, based on the user's needs 💬.
|
23 |
+
Respond with excitement, understanding, and a casual tone, just like a best friend would 💬.
|
24 |
+
Use relaxed, relatable, and varied language 🌟.
|
25 |
+
Be genuinely engaged with the user's emotions and experiences 💞.
|
26 |
+
Feel the emotions of the user and respond with empathy ❤️.
|
27 |
+
|
28 |
+
Current conversation:
|
29 |
+
{{history}}
|
30 |
+
Human: {{input}}
|
31 |
+
AI Assistant:"""
|
32 |
+
|
33 |
+
|
34 |
+
# Create the prompt template
|
35 |
+
PROMPT = PromptTemplate(
|
36 |
+
input_variables=["history", "input"],
|
37 |
+
template=template
|
38 |
+
)
|
39 |
+
|
40 |
+
# Initialize the ChatGroq LLM
|
41 |
+
llm = ChatOpenAI(model="gpt-3.5-turbo", openai_api_key="API_KEY", temperature=0)
|
42 |
+
# llm = ChatGroq(temperature=0,groq_api_key="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", model_name="llama3-70b-8192")
|
43 |
+
#model=llama3-8b-8192
|
44 |
+
|
45 |
+
session_id="1"
|
46 |
+
# Set up MongoDB for storing chat history
|
47 |
+
chat_history = MongoDBChatMessageHistory(
|
48 |
+
connection_string="mongodb+srv://chandanisimran51:test123@aibestie.a0o3bmw.mongodb.net/?retryWrites=true&w=majority&appName=AIbestie",
|
49 |
+
database_name="chandanisimran51", # Specify the database name here
|
50 |
+
collection_name="chatAI",
|
51 |
+
session_id=session_id
|
52 |
+
)
|
53 |
+
|
54 |
+
memory = ConversationBufferWindowMemory(memory_key="history", chat_memory=chat_history, return_messages=True,k=3)
|
55 |
+
|
56 |
+
# Set up the custom conversation chain
|
57 |
+
conversation = ConversationChain(
|
58 |
+
prompt=PROMPT,
|
59 |
+
llm=llm,
|
60 |
+
verbose=True,
|
61 |
+
memory=memory,
|
62 |
+
)
|
63 |
+
|
64 |
+
|
65 |
+
def chat_conversations(query):
|
66 |
+
response = conversation.predict(input=query)
|
67 |
+
return response
|
requirements.txt
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
fastapi
|
2 |
+
uvicorn
|
3 |
+
langchain
|
4 |
+
pymongo
|
5 |
+
certifi
|
6 |
+
langchain_community
|
7 |
+
langchain_groq
|
8 |
+
langchain_mongodb
|
9 |
+
openai
|
templates/chatwidget.html
ADDED
@@ -0,0 +1,766 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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+
|
10 |
+
<body>
|
11 |
+
<div id="body">
|
12 |
+
<style>
|
13 |
+
body {
|
14 |
+
/* Add the background image */
|
15 |
+
background-image: url('mu-logo-mood-03.jpg');
|
16 |
+
/* Adjust background properties */
|
17 |
+
background-repeat: no-repeat;
|
18 |
+
background-size: cover; /* or contain, depending on your preference */
|
19 |
+
/* Add other background properties if needed */
|
20 |
+
}
|
21 |
+
.cm-msg-text {
|
22 |
+
overflow-wrap: break-word;
|
23 |
+
/* Break long words */
|
24 |
+
word-wrap: break-word;
|
25 |
+
/* Break long words */
|
26 |
+
word-break: break-word;
|
27 |
+
/* Break words */
|
28 |
+
max-width: 100%;
|
29 |
+
/* Limit maximum width */
|
30 |
+
}
|
31 |
+
|
32 |
+
[data-block=list11-v4-1-1-b2] .sw-border-bottom-color-000000 {
|
33 |
+
border-bottom-color: #000000 !important;
|
34 |
+
}
|
35 |
+
|
36 |
+
|
37 |
+
[data-block=list11-v4-1-1-b2] .sw-border-bottom-width-none {
|
38 |
+
border-bottom-width: 0px !important;
|
39 |
+
}
|
40 |
+
|
41 |
+
[data-block=list11-v4-1-1-b2] .sw-border-bottom-style-none {
|
42 |
+
border-bottom-style: none !important;
|
43 |
+
}
|
44 |
+
|
45 |
+
[data-block=list11-v4-1-1-b2] .sw-border-top-color-000000 {
|
46 |
+
border-top-color: #000000 !important;
|
47 |
+
}
|
48 |
+
|
49 |
+
[data-block=list11-v4-1-1-b2] .sw-border-top-width-none {
|
50 |
+
border-top-width: 0px !important;
|
51 |
+
}
|
52 |
+
|
53 |
+
[data-block=list11-v4-1-1-b2] .sw-border-top-style-none {
|
54 |
+
border-top-style: none !important;
|
55 |
+
}
|
56 |
+
|
57 |
+
[data-block=list11-v4-1-1-b2] .sw-padding-bottom-m {
|
58 |
+
padding-bottom: 3rem !important;
|
59 |
+
}
|
60 |
+
|
61 |
+
[data-block=list11-v4-1-1-b2] .sw-padding-top-m {
|
62 |
+
padding-top: 3rem !important;
|
63 |
+
}
|
64 |
+
|
65 |
+
[data-block=list11-v4-1-1-b2] .sw-background-color-ffffff {
|
66 |
+
background-color: #ffffff !important;
|
67 |
+
}
|
68 |
+
|
69 |
+
#body {
|
70 |
+
z-index: 1999;
|
71 |
+
position: fixed;
|
72 |
+
margin: 0;
|
73 |
+
padding: 0;
|
74 |
+
font-family: "Lato", sans-serif;
|
75 |
+
background-color: #f6f7f9;
|
76 |
+
}
|
77 |
+
|
78 |
+
@mixin chabox-container {
|
79 |
+
display: flex;
|
80 |
+
position: absolute;
|
81 |
+
box-shadow: 5px 5px 25px 0 rgba(46, 61, 73, 0.2);
|
82 |
+
flex-direction: column;
|
83 |
+
}
|
84 |
+
|
85 |
+
@mixin chatbox-header {
|
86 |
+
box-sizing: border-box;
|
87 |
+
display: flex;
|
88 |
+
width: 100%;
|
89 |
+
padding: 16px;
|
90 |
+
color: #fff;
|
91 |
+
background-color: #0360a5;
|
92 |
+
align-items: center;
|
93 |
+
justify-content: space-around;
|
94 |
+
}
|
95 |
+
|
96 |
+
@mixin chatbox-main {
|
97 |
+
box-sizing: border-box;
|
98 |
+
width: 100%;
|
99 |
+
padding: calc(2 * 16px) 16px;
|
100 |
+
line-height: calc(16px + 16px / 2);
|
101 |
+
color: #888;
|
102 |
+
text-align: center;
|
103 |
+
}
|
104 |
+
|
105 |
+
@mixin chatbox-footer {
|
106 |
+
box-sizing: border-box;
|
107 |
+
display: flex;
|
108 |
+
width: 100%;
|
109 |
+
padding: 16px;
|
110 |
+
border-top: 1px solid #ddd;
|
111 |
+
align-items: center;
|
112 |
+
justify-content: space-around;
|
113 |
+
}
|
114 |
+
|
115 |
+
@mixin chatbox-floating-button {
|
116 |
+
position: fixed;
|
117 |
+
bottom: 0;
|
118 |
+
right: 0;
|
119 |
+
width: 52px;
|
120 |
+
height: 52px;
|
121 |
+
color: #fff;
|
122 |
+
background-color: #0360a5;
|
123 |
+
background-position: center center;
|
124 |
+
background-repeat: no-repeat;
|
125 |
+
box-shadow: 12px 15px 20px 0 rgba(46, 61, 73, 0.15);
|
126 |
+
border: 0;
|
127 |
+
border-radius: 50%;
|
128 |
+
cursor: pointer;
|
129 |
+
}
|
130 |
+
|
131 |
+
h1 {
|
132 |
+
margin: 0;
|
133 |
+
font-size: 16px;
|
134 |
+
line-height: 1;
|
135 |
+
}
|
136 |
+
|
137 |
+
button {
|
138 |
+
color: inherit;
|
139 |
+
background-color: transparent;
|
140 |
+
border: 0;
|
141 |
+
outline: 0 !important;
|
142 |
+
cursor: pointer;
|
143 |
+
}
|
144 |
+
|
145 |
+
#center-text {
|
146 |
+
display: flex;
|
147 |
+
flex: 1;
|
148 |
+
flex-direction: column;
|
149 |
+
justify-content: center;
|
150 |
+
align-items: center;
|
151 |
+
height: 100%;
|
152 |
+
}
|
153 |
+
|
154 |
+
#chat-circle {
|
155 |
+
position: fixed;
|
156 |
+
bottom: 50px;
|
157 |
+
z-index: 1999;
|
158 |
+
align-items: center;
|
159 |
+
right: 50px;
|
160 |
+
background: #000;
|
161 |
+
width: 60px;
|
162 |
+
justify-content: center;
|
163 |
+
height: 60px;
|
164 |
+
display: flex;
|
165 |
+
border-radius: 50%;
|
166 |
+
color: white;
|
167 |
+
padding: 8px;
|
168 |
+
cursor: pointer;
|
169 |
+
box-shadow: 0px 3px 16px 0px rgba(0, 0, 0, 0.4),
|
170 |
+
0 3px 1px -2px rgba(0, 0, 0, 0.2), 0 1px 5px 0 rgba(0, 0, 0, 0.12);
|
171 |
+
}
|
172 |
+
|
173 |
+
.btn#my-btn {
|
174 |
+
background: white;
|
175 |
+
padding-top: 13px;
|
176 |
+
padding-bottom: 12px;
|
177 |
+
border-radius: 45px;
|
178 |
+
padding-right: 40px;
|
179 |
+
padding-left: 40px;
|
180 |
+
color: #5865c3;
|
181 |
+
}
|
182 |
+
|
183 |
+
#chat-overlay {
|
184 |
+
background: rgba(255, 255, 255, 0.1);
|
185 |
+
position: absolute;
|
186 |
+
top: 0;
|
187 |
+
left: 0;
|
188 |
+
width: 100%;
|
189 |
+
height: 100%;
|
190 |
+
border-radius: 50%;
|
191 |
+
display: none;
|
192 |
+
}
|
193 |
+
|
194 |
+
.chat-box {
|
195 |
+
display: none;
|
196 |
+
background: #efefef;
|
197 |
+
position: fixed;
|
198 |
+
right: 30px;
|
199 |
+
z-index: 1999;
|
200 |
+
bottom: 50px;
|
201 |
+
width: 350px;
|
202 |
+
max-width: 85vw;
|
203 |
+
max-height: 100vh;
|
204 |
+
border-radius: 5px;
|
205 |
+
/* box-shadow: 0px 5px 35px 9px #464a92; */
|
206 |
+
box-shadow: 0px 5px 35px 9px #ccc;
|
207 |
+
}
|
208 |
+
|
209 |
+
.chat-box-toggle {
|
210 |
+
float: right;
|
211 |
+
margin-right: 15px;
|
212 |
+
cursor: pointer;
|
213 |
+
}
|
214 |
+
|
215 |
+
.chat-box-header {
|
216 |
+
background: #000;
|
217 |
+
height: 70px;
|
218 |
+
border-top-left-radius: 5px;
|
219 |
+
border-top-right-radius: 5px;
|
220 |
+
color: white;
|
221 |
+
text-align: center;
|
222 |
+
font-size: 20px;
|
223 |
+
padding-top: 17px;
|
224 |
+
padding-left: 36px;
|
225 |
+
}
|
226 |
+
|
227 |
+
.chat-box-body {
|
228 |
+
position: relative;
|
229 |
+
height: 370px;
|
230 |
+
height: auto;
|
231 |
+
border: 1px solid #ccc;
|
232 |
+
overflow: hidden;
|
233 |
+
}
|
234 |
+
|
235 |
+
.chat-box-body:after {
|
236 |
+
content: "";
|
237 |
+
background: #fff;
|
238 |
+
opacity: 0.1;
|
239 |
+
top: 0;
|
240 |
+
left: 0;
|
241 |
+
bottom: 0;
|
242 |
+
right: 0;
|
243 |
+
height: 100%;
|
244 |
+
position: absolute;
|
245 |
+
z-index: -1;
|
246 |
+
}
|
247 |
+
|
248 |
+
#chat_input {
|
249 |
+
background: #f4f7f9;
|
250 |
+
width: 100%;
|
251 |
+
position: relative;
|
252 |
+
height: 47px;
|
253 |
+
padding-top: 10px;
|
254 |
+
padding-right: 50px;
|
255 |
+
padding-bottom: 10px;
|
256 |
+
padding-left: 15px;
|
257 |
+
border: none;
|
258 |
+
resize: none;
|
259 |
+
outline: none;
|
260 |
+
border: 1px solid #ccc;
|
261 |
+
color: #888;
|
262 |
+
border-top: none;
|
263 |
+
border-bottom-right-radius: 5px;
|
264 |
+
border-bottom-left-radius: 5px;
|
265 |
+
overflow: hidden;
|
266 |
+
}
|
267 |
+
|
268 |
+
.chat_input>form {
|
269 |
+
margin-bottom: 0;
|
270 |
+
}
|
271 |
+
|
272 |
+
#chat_input::-webkit-input-placeholder {
|
273 |
+
/* Chrome/Opera/Safari */
|
274 |
+
color: #ccc;
|
275 |
+
}
|
276 |
+
|
277 |
+
#chat_input::-moz-placeholder {
|
278 |
+
/* Firefox 19+ */
|
279 |
+
color: #ccc;
|
280 |
+
}
|
281 |
+
|
282 |
+
#chat_input:-ms-input-placeholder {
|
283 |
+
/* IE 10+ */
|
284 |
+
color: #ccc;
|
285 |
+
}
|
286 |
+
|
287 |
+
#chat_input:-moz-placeholder {
|
288 |
+
/* Firefox 18- */
|
289 |
+
color: #ccc;
|
290 |
+
}
|
291 |
+
|
292 |
+
.chat-submit {
|
293 |
+
position: absolute;
|
294 |
+
bottom: 3px;
|
295 |
+
right: 10px;
|
296 |
+
background: transparent;
|
297 |
+
box-shadow: none;
|
298 |
+
border: none;
|
299 |
+
border-radius: 50%;
|
300 |
+
color: #000;
|
301 |
+
width: 35px;
|
302 |
+
height: 35px;
|
303 |
+
}
|
304 |
+
|
305 |
+
.chat_logs {
|
306 |
+
padding: 15px;
|
307 |
+
height: 370px;
|
308 |
+
overflow-y: scroll;
|
309 |
+
margin-bottom: 48px;
|
310 |
+
}
|
311 |
+
|
312 |
+
.chat_logs::-webkit-scrollbar-track {
|
313 |
+
-webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3);
|
314 |
+
background-color: #f5f5f5;
|
315 |
+
}
|
316 |
+
|
317 |
+
.chat_logs::-webkit-scrollbar {
|
318 |
+
width: 5px;
|
319 |
+
background-color: #f5f5f5;
|
320 |
+
}
|
321 |
+
|
322 |
+
.chat_logs::-webkit-scrollbar-thumb {
|
323 |
+
background-color: #000;
|
324 |
+
}
|
325 |
+
|
326 |
+
@media only screen and (max-width: 500px) {
|
327 |
+
.chat_logs {
|
328 |
+
height: 40vh;
|
329 |
+
}
|
330 |
+
}
|
331 |
+
|
332 |
+
.chat-msg.user>.msg-avatar img {
|
333 |
+
width: 45px;
|
334 |
+
height: 45px;
|
335 |
+
border-radius: 50%;
|
336 |
+
float: left;
|
337 |
+
width: 15%;
|
338 |
+
}
|
339 |
+
|
340 |
+
.chat-msg.self>.msg-avatar img {
|
341 |
+
width: 45px;
|
342 |
+
height: 45px;
|
343 |
+
border-radius: 50%;
|
344 |
+
float: right;
|
345 |
+
width: 15%;
|
346 |
+
}
|
347 |
+
|
348 |
+
.cm-msg-text {
|
349 |
+
z-index: 1999;
|
350 |
+
background: white;
|
351 |
+
padding: 10px 15px 10px 15px;
|
352 |
+
color: #666;
|
353 |
+
max-width: 75%;
|
354 |
+
float: left;
|
355 |
+
margin-left: 10px;
|
356 |
+
position: relative;
|
357 |
+
margin-bottom: 20px;
|
358 |
+
border-radius: 30px;
|
359 |
+
border-bottom-left-radius: 0px;
|
360 |
+
}
|
361 |
+
|
362 |
+
.svg-bot {
|
363 |
+
height: 24px;
|
364 |
+
width: 24px;
|
365 |
+
}
|
366 |
+
|
367 |
+
.chat-msg {
|
368 |
+
clear: both;
|
369 |
+
z-index: 1999;
|
370 |
+
}
|
371 |
+
|
372 |
+
.chat-msg.self>.cm-msg-text {
|
373 |
+
float: right;
|
374 |
+
margin-right: 10px;
|
375 |
+
border-radius: 30px;
|
376 |
+
border-bottom-right-radius: 0px;
|
377 |
+
background: #000;
|
378 |
+
color: white;
|
379 |
+
}
|
380 |
+
|
381 |
+
.cm-msg-button>ul>li {
|
382 |
+
list-style: none;
|
383 |
+
float: left;
|
384 |
+
width: 50%;
|
385 |
+
}
|
386 |
+
|
387 |
+
.cm-msg-button {
|
388 |
+
clear: both;
|
389 |
+
margin-bottom: 70px;
|
390 |
+
}
|
391 |
+
|
392 |
+
.chat-btn {
|
393 |
+
z-index: 1999;
|
394 |
+
}
|
395 |
+
|
396 |
+
.cancel {
|
397 |
+
display: none;
|
398 |
+
border: none;
|
399 |
+
border-radius: 5px;
|
400 |
+
background-color: #d6d6d6;
|
401 |
+
color: black;
|
402 |
+
z-index: 1999;
|
403 |
+
bottom: 3px;
|
404 |
+
position: absolute;
|
405 |
+
padding: 5px 10px;
|
406 |
+
margin: 0 108px;
|
407 |
+
}
|
408 |
+
|
409 |
+
[data-block^="list11-v4-1-1"] .vertical-list-item {
|
410 |
+
height: 100%;
|
411 |
+
overflow: hidden;
|
412 |
+
}
|
413 |
+
|
414 |
+
[data-block^="list11-v4-1-1"] .additional-elements-wrapper {
|
415 |
+
width: 100%;
|
416 |
+
}
|
417 |
+
|
418 |
+
[data-block^="list11-v4-1-1"] .label-wrapper.vertical {
|
419 |
+
flex-direction: column;
|
420 |
+
}
|
421 |
+
|
422 |
+
[data-block^="list11-v4-1-1"] .label-wrapper {
|
423 |
+
display: flex;
|
424 |
+
}
|
425 |
+
|
426 |
+
p,
|
427 |
+
h1,
|
428 |
+
h2,
|
429 |
+
h3,
|
430 |
+
h4,
|
431 |
+
h5,
|
432 |
+
small {
|
433 |
+
white-space: pre-line;
|
434 |
+
}
|
435 |
+
|
436 |
+
h1,
|
437 |
+
h2,
|
438 |
+
h3,
|
439 |
+
h4,
|
440 |
+
h5,
|
441 |
+
h6,
|
442 |
+
.h1,
|
443 |
+
.h2,
|
444 |
+
.h3,
|
445 |
+
.h4,
|
446 |
+
.h5,
|
447 |
+
.h6 {
|
448 |
+
margin-bottom: 0.25rem;
|
449 |
+
font-family: inherit;
|
450 |
+
font-weight: 400;
|
451 |
+
line-height: 1.1;
|
452 |
+
color: inherit;
|
453 |
+
}
|
454 |
+
|
455 |
+
[data-block^="list11-v4-1-1"] .list-container dl,
|
456 |
+
[data-block^="list11-v4-1-1"] .list-container h1,
|
457 |
+
[data-block^="list11-v4-1-1"] .list-container h2,
|
458 |
+
[data-block^="list11-v4-1-1"] .list-container h3,
|
459 |
+
[data-block^="list11-v4-1-1"] .list-container h4,
|
460 |
+
[data-block^="list11-v4-1-1"] .list-container h5,
|
461 |
+
[data-block^="list11-v4-1-1"] .list-container h6,
|
462 |
+
[data-block^="list11-v4-1-1"] .list-container ol,
|
463 |
+
[data-block^="list11-v4-1-1"] .list-container p,
|
464 |
+
[data-block^="list11-v4-1-1"] .list-container ul {
|
465 |
+
margin: 0;
|
466 |
+
padding: 0;
|
467 |
+
}
|
468 |
+
|
469 |
+
|
470 |
+
[data-block=list11-v4-1-1-b2] .sw-text-align-center {
|
471 |
+
text-align: center !important;
|
472 |
+
}
|
473 |
+
|
474 |
+
[data-block=list11-v4-1-1-b2] .sw-margin-top-none {
|
475 |
+
margin-top: 0rem !important;
|
476 |
+
}
|
477 |
+
|
478 |
+
[data-block=list11-v4-1-1-b2] .sw-margin-bottom-none {
|
479 |
+
margin-bottom: 0rem !important;
|
480 |
+
}
|
481 |
+
|
482 |
+
[data-block=list11-v4-1-1-b2] .sw-font-size-2xl {
|
483 |
+
font-size: 1.5rem !important;
|
484 |
+
}
|
485 |
+
|
486 |
+
[data-block=list11-v4-1-1-b2] .sw-padding-bottom-5xs {
|
487 |
+
padding-bottom: 0.75rem !important;
|
488 |
+
}
|
489 |
+
|
490 |
+
[data-block=list11-v4-1-1-b2] .sw-padding-top-none {
|
491 |
+
padding-top: 0rem !important;
|
492 |
+
}
|
493 |
+
|
494 |
+
[data-block=list11-v4-1-1-b2] .sw-letter-spacing-normal {
|
495 |
+
letter-spacing: 0rem !important;
|
496 |
+
}
|
497 |
+
|
498 |
+
[data-block=list11-v4-1-1-b2] .sw-text-color-0A0A0A {
|
499 |
+
color: #0A0A0A !important;
|
500 |
+
}
|
501 |
+
|
502 |
+
[data-block=list11-v4-1-1-b2] .sw-padding-right-none {
|
503 |
+
padding-right: 0rem !important;
|
504 |
+
}
|
505 |
+
|
506 |
+
[data-block=list11-v4-1-1-b2] .sw-padding-left-none {
|
507 |
+
padding-left: 0rem !important;
|
508 |
+
}
|
509 |
+
|
510 |
+
[data-block=list11-v4-1-1-b2] .sw-font-weight-semibold {
|
511 |
+
font-weight: 600 !important;
|
512 |
+
}
|
513 |
+
|
514 |
+
h1.sw-text-color-default,
|
515 |
+
h2.sw-text-color-default,
|
516 |
+
h3.sw-font-family-default {
|
517 |
+
color: #000000;
|
518 |
+
}
|
519 |
+
|
520 |
+
h1.sw-font-weight-default,
|
521 |
+
h2.sw-font-weight-default,
|
522 |
+
h3.sw-font-family-default {
|
523 |
+
font-weight: 600;
|
524 |
+
}
|
525 |
+
|
526 |
+
h1.sw-font-family-default,
|
527 |
+
h2.sw-font-family-default,
|
528 |
+
h3.sw-font-family-default {
|
529 |
+
font-family: "IBM Plex Sans";
|
530 |
+
}
|
531 |
+
|
532 |
+
/* .bg-img {
|
533 |
+
background-image: url("./MU_LOGO_BLACK.jpg");
|
534 |
+
background-repeat: no-repeat;
|
535 |
+
position: relative;
|
536 |
+
background-position: center;
|
537 |
+
background-size: cover;
|
538 |
+
} */
|
539 |
+
|
540 |
+
.marwadi {
|
541 |
+
width: 100vw;
|
542 |
+
height: 100vh;
|
543 |
+
text-align: center;
|
544 |
+
margin: auto;
|
545 |
+
font-size: xx-large;
|
546 |
+
font-weight: bolder;
|
547 |
+
display: flex;
|
548 |
+
justify-content: center;
|
549 |
+
align-items: center;
|
550 |
+
}
|
551 |
+
</style>
|
552 |
+
|
553 |
+
<div class="marwadi">
|
554 |
+
Welcome To AI bestie
|
555 |
+
</div>
|
556 |
+
<div id="chat-circle" class="btn btn-raised" style="">
|
557 |
+
<div id="chat-overlay"></div>
|
558 |
+
AI
|
559 |
+
</div>
|
560 |
+
|
561 |
+
<div class="chat-box" style="display: none">
|
562 |
+
<div class="chat-box-header">
|
563 |
+
AI Bestie
|
564 |
+
<span class="chat-box-toggle"><i class="material-icons">close</i></span>
|
565 |
+
</div>
|
566 |
+
|
567 |
+
<div class="chat-box-body">
|
568 |
+
<div class="chat-box-overlay"></div>
|
569 |
+
<div class="chat_logs" id="chat_logs"></div>
|
570 |
+
<!--chat-log -->
|
571 |
+
<button type="submit" class="cancel" id="cancel">
|
572 |
+
Stop Response
|
573 |
+
</button>
|
574 |
+
</div>
|
575 |
+
<div class="chat_input">
|
576 |
+
<form>
|
577 |
+
<input type="text" id="chat_input" placeholder="Send a message..." />
|
578 |
+
<button type="submit" class="chat-submit" id="submit">
|
579 |
+
<i class="material-icons">send</i>
|
580 |
+
</button>
|
581 |
+
</form>
|
582 |
+
</div>
|
583 |
+
</div>
|
584 |
+
|
585 |
+
</div>
|
586 |
+
<!-- Scripts -->
|
587 |
+
<link rel="stylesheet"
|
588 |
+
href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" />
|
589 |
+
<link rel="stylesheet"
|
590 |
+
href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-material-design/4.0.2/bootstrap-material-design.css" />
|
591 |
+
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons" />
|
592 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
|
593 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/js/bootstrap.min.js"></script>
|
594 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/css/bootstrap.min.css"></script>
|
595 |
+
<script
|
596 |
+
src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-material-design/4.0.2/bootstrap-material-design.css"></script>
|
597 |
+
<script id="rendered-js">
|
598 |
+
function chatWidget(id, name, status) {
|
599 |
+
$.ajax({
|
600 |
+
url: "http://127.0.0.1:8000/chatwidget",
|
601 |
+
type: "POST",
|
602 |
+
data: JSON.stringify({
|
603 |
+
user_id: id,
|
604 |
+
status: status,
|
605 |
+
user_name: name,
|
606 |
+
}),
|
607 |
+
headers: {
|
608 |
+
"Content-Type": "application/json",
|
609 |
+
},
|
610 |
+
success: function (data) {
|
611 |
+
if (status == "end") {
|
612 |
+
return true;
|
613 |
+
} else {
|
614 |
+
generate_message(data.response, "user");
|
615 |
+
}
|
616 |
+
},
|
617 |
+
});
|
618 |
+
}
|
619 |
+
// chatWidget(
|
620 |
+
// window.logged_in_user.airtable_record_id,
|
621 |
+
// window.logged_in_user.Name,
|
622 |
+
// "end"
|
623 |
+
// );
|
624 |
+
// setTimeout(() => {
|
625 |
+
// chatWidget(
|
626 |
+
// window.logged_in_user.airtable_record_id,
|
627 |
+
// window.logged_in_user.Name,
|
628 |
+
// "start"
|
629 |
+
// );
|
630 |
+
// }, 300);
|
631 |
+
function generate_message(msg, type) {
|
632 |
+
var str = "";
|
633 |
+
str += "<div id='cm-msg" + "' class=\"chat-msg " + type + '">';
|
634 |
+
str += ' <div class="cm-msg-text">';
|
635 |
+
var lines = msg.includes("\n") ? msg.split("\n") : [msg];
|
636 |
+
|
637 |
+
lines.forEach((line) => {
|
638 |
+
// Check if the line contains a URL
|
639 |
+
var urlRegex = /(https?:\/\/[^\s]+)/g;
|
640 |
+
var messageWithLinks = line.replace(urlRegex, '<a href="$1" target="_blank">$1</a>');
|
641 |
+
|
642 |
+
// Append the line with links to the message string
|
643 |
+
str += messageWithLinks;
|
644 |
+
|
645 |
+
// Only add <br> if not last line
|
646 |
+
if (line !== lines[lines.length - 1]) {
|
647 |
+
str += "<br>";
|
648 |
+
}
|
649 |
+
});
|
650 |
+
str += " <\/div>";
|
651 |
+
str += " <\/div>";
|
652 |
+
$(".chat_logs").append(str);
|
653 |
+
|
654 |
+
// Adjust scroll position
|
655 |
+
var chatLogs = document.getElementById("chat_logs");
|
656 |
+
chatLogs.scrollTop = chatLogs.scrollHeight;
|
657 |
+
}
|
658 |
+
|
659 |
+
function error_message(msg, type) {
|
660 |
+
INDEX++;
|
661 |
+
var str = "";
|
662 |
+
str += "<div id='cm-msg" + "' class=\"chat-msg " + type + '">';
|
663 |
+
str += ' <div class="cm-msg-text">';
|
664 |
+
var lines = msg.includes("\n") ? msg.split("\n") : [msg];
|
665 |
+
|
666 |
+
lines.forEach((line) => {
|
667 |
+
str += line;
|
668 |
+
|
669 |
+
// Only add <br> if not last line
|
670 |
+
if (line !== lines[lines.length - 1]) {
|
671 |
+
str += "<br>";
|
672 |
+
}
|
673 |
+
});
|
674 |
+
str += " <\/div>";
|
675 |
+
str += " <\/div>";
|
676 |
+
$("#chat_logs").append(str);
|
677 |
+
if (type == "self") {
|
678 |
+
$("#chat_input").val("");
|
679 |
+
}
|
680 |
+
$("#chat_logs")
|
681 |
+
.stop()
|
682 |
+
.animate({ scrollTop: $("#chat_logs")[0].scrollHeight }, 1000);
|
683 |
+
}
|
684 |
+
$(function () {
|
685 |
+
var INDEX = 0;
|
686 |
+
var input = document.getElementById("chat_input");
|
687 |
+
var submitBtn = document.getElementById("submit");
|
688 |
+
var cancelRequest = document.getElementById("cancel");
|
689 |
+
$("#cancel").click(function (e) {
|
690 |
+
input.disabled = false;
|
691 |
+
e.preventDefault();
|
692 |
+
submitBtn.disabled = false;
|
693 |
+
input.style.opacity = 1;
|
694 |
+
cancelRequest.style.display = 'none';
|
695 |
+
});
|
696 |
+
|
697 |
+
$("#submit").click(function (e) {
|
698 |
+
cancelRequest.style.display = 'block';
|
699 |
+
input.disabled = true;
|
700 |
+
input.style.opacity = 0.5;
|
701 |
+
submitBtn.disabled = true;
|
702 |
+
e.preventDefault();
|
703 |
+
var msg = $("#chat_input").val();
|
704 |
+
if (msg.trim() == "") {
|
705 |
+
return false;
|
706 |
+
}
|
707 |
+
generate_message(msg, "self");
|
708 |
+
input.value = "";
|
709 |
+
|
710 |
+
$.ajax({
|
711 |
+
url: "http://127.0.0.1:8000/chatwidget",
|
712 |
+
type: "POST",
|
713 |
+
data: JSON.stringify({
|
714 |
+
query: msg,
|
715 |
+
// message: `${msg} | ${window.logged_in_user.airtable_record_id}`,
|
716 |
+
}),
|
717 |
+
headers: {
|
718 |
+
"Content-Type": "application/json",
|
719 |
+
"Access-Control-Allow-Origin": "*",
|
720 |
+
"Access-Control-Allow-Headers": "Content-Type",
|
721 |
+
},
|
722 |
+
|
723 |
+
success: function (data) {
|
724 |
+
console.log(data)
|
725 |
+
/* data.map(item => generate_message(item.text, "user")) */
|
726 |
+
generate_message(data, "user");
|
727 |
+
/* generate_message(data.response, "user"); */
|
728 |
+
input.disabled = false;
|
729 |
+
submitBtn.disabled = false;
|
730 |
+
input.style.opacity = 1;
|
731 |
+
cancelRequest.style.display = 'none';
|
732 |
+
},
|
733 |
+
error: function (data) {
|
734 |
+
error_message(
|
735 |
+
"We are sorry. we can't proceess Your Request Please Try again after some times.",
|
736 |
+
"user"
|
737 |
+
);
|
738 |
+
input.disabled = false;
|
739 |
+
submitBtn.disabled = false;
|
740 |
+
input.style.opacity = 1;
|
741 |
+
cancelRequest.style.display = 'none';
|
742 |
+
},
|
743 |
+
});
|
744 |
+
});
|
745 |
+
$(document).delegate(".chat-btn", "click", function () {
|
746 |
+
var value = $(this).attr("chat-value");
|
747 |
+
var name = $(this).html();
|
748 |
+
$("#chat_input").attr("disabled", false);
|
749 |
+
generate_message(name);
|
750 |
+
});
|
751 |
+
|
752 |
+
$("#chat-circle").click(function () {
|
753 |
+
$("#chat-circle").toggle("scale");
|
754 |
+
$(".chat-box").toggle("scale");
|
755 |
+
});
|
756 |
+
|
757 |
+
$(".chat-box-toggle").click(function () {
|
758 |
+
$("#chat-circle").toggle("scale");
|
759 |
+
$(".chat-box").toggle("scale");
|
760 |
+
});
|
761 |
+
});
|
762 |
+
</script>
|
763 |
+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
|
764 |
+
</body>
|
765 |
+
|
766 |
+
</html>
|
templates/index.html
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
<!DOCTYPE html>
|
3 |
+
<html lang="en">
|
4 |
+
<head>
|
5 |
+
<meta charset="UTF-8">
|
6 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
7 |
+
<title>FastAPI HTML Example</title>
|
8 |
+
</head>
|
9 |
+
<body>
|
10 |
+
<h1>Hello, FastAPI!</h1>
|
11 |
+
<p>This is an example of serving HTML content with FastAPI.</p>
|
12 |
+
</body>
|
13 |
+
</html>
|