Yjhhh commited on
Commit
a8269a5
1 Parent(s): 3b48158

Upload 2 files

Browse files
Files changed (2) hide show
  1. index.html +268 -0
  2. requirements.txt +36 -0
index.html ADDED
@@ -0,0 +1,268 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Chatbot</title>
7
+ <style>
8
+ body {
9
+ font-family: Arial, sans-serif;
10
+ margin: 0;
11
+ padding: 0;
12
+ background-color: #f5f5f5;
13
+ }
14
+ .container {
15
+ max-width: 800px;
16
+ margin: 0 auto;
17
+ padding: 20px;
18
+ background-color: #fff;
19
+ border-radius: 5px;
20
+ box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
21
+ margin-top: 50px;
22
+ }
23
+ h1 {
24
+ text-align: center;
25
+ color: #333;
26
+ }
27
+ form {
28
+ text-align: center;
29
+ margin-top: 20px;
30
+ }
31
+ input[type="text"], input[type="file"] {
32
+ width: 70%;
33
+ padding: 10px;
34
+ border: 1px solid #ccc;
35
+ border-radius: 5px;
36
+ font-size: 16px;
37
+ margin-bottom: 10px;
38
+ }
39
+ input[type="submit"] {
40
+ padding: 10px 20px;
41
+ background-color: #007bff;
42
+ color: #fff;
43
+ border: none;
44
+ border-radius: 5px;
45
+ cursor: pointer;
46
+ font-size: 16px;
47
+ margin-bottom: 10px;
48
+ }
49
+ .chat-history {
50
+ margin-top: 20px;
51
+ border-top: 1px solid #ccc;
52
+ padding-top: 20px;
53
+ overflow-y: scroll;
54
+ height: 300px;
55
+ }
56
+ .chat-message {
57
+ margin-bottom: 10px;
58
+ display: grid;
59
+ grid-template-columns: auto auto;
60
+ column-gap: 10px;
61
+ }
62
+ .user-message {
63
+ text-align: right;
64
+ color: #007bff;
65
+ }
66
+ .system-message {
67
+ text-align: left;
68
+ color: #333;
69
+ }
70
+ .content-preview {
71
+ margin-top: 20px;
72
+ text-align: center;
73
+ }
74
+ img {
75
+ max-width: 100%;
76
+ height: auto;
77
+ margin-top: 10px;
78
+ }
79
+ video {
80
+ max-width: 100%;
81
+ height: auto;
82
+ margin-top: 10px;
83
+ }
84
+ </style>
85
+ </head>
86
+ <body>
87
+ <div class="container">
88
+ <h1>Welcome to the Chatbot</h1>
89
+ <div class="chat-history" id="chat-history">
90
+ <!-- Chat messages will be displayed here -->
91
+ </div>
92
+ <div class="content-preview" id="content-preview">
93
+ <!-- Content preview will be displayed here -->
94
+ </div>
95
+ <form id="chat-form">
96
+ <input type="text" id="question" placeholder="Type your question here...">
97
+ <input type="submit" value="Ask">
98
+ </form>
99
+ <form id="audio-form" enctype="multipart/form-data">
100
+ <input type="file" id="audio-file" accept="audio/*">
101
+ <input type="submit" value="Upload Audio">
102
+ </form>
103
+ <form id="image-form">
104
+ <input type="text" id="image-prompt" placeholder="Describe the image you want...">
105
+ <input type="submit" value="Generate Image">
106
+ </form>
107
+ <form id="video-form">
108
+ <input type="text" id="video-prompt" placeholder="Describe the video you want...">
109
+ <input type="submit" value="Generate Video">
110
+ </form>
111
+ <form id="summarize-text-form">
112
+ <input type="text" id="text-to-summarize" placeholder="Enter text to summarize...">
113
+ <input type="submit" value="Summarize Text">
114
+ </form>
115
+ <form id="summarize-file-form" enctype="multipart/form-data">
116
+ <input type="file" id="file-to-summarize" accept=".txt,.pdf,.docx">
117
+ <input type="submit" value="Summarize File">
118
+ </form>
119
+ <div id="response-container">
120
+ <!-- Response content will be displayed here -->
121
+ </div>
122
+ </div>
123
+ <script>
124
+ const chatForm = document.getElementById('chat-form');
125
+ const audioForm = document.getElementById('audio-form');
126
+ const imageForm = document.getElementById('image-form');
127
+ const videoForm = document.getElementById('video-form');
128
+ const summarizeTextForm = document.getElementById('summarize-text-form');
129
+ const summarizeFileForm = document.getElementById('summarize-file-form');
130
+ const chatHistory = document.getElementById('chat-history');
131
+ const contentPreview = document.getElementById('content-preview');
132
+ const responseContainer = document.getElementById('response-container');
133
+
134
+ function displayMessage(message, type) {
135
+ const messageElement = document.createElement('div');
136
+ messageElement.classList.add('chat-message');
137
+ messageElement.innerHTML = `<span class="${type}-message">${message}</span>`;
138
+ chatHistory.appendChild(messageElement);
139
+ chatHistory.scrollTop = chatHistory.scrollHeight;
140
+ }
141
+
142
+ function displayResponse(response) {
143
+ responseContainer.innerHTML = ''; // Clear previous response
144
+ if (typeof response === 'string') {
145
+ displayMessage(response, 'system');
146
+ } else if (response instanceof Blob) {
147
+ const url = URL.createObjectURL(response);
148
+ if (response.type.startsWith('image/')) {
149
+ const img = document.createElement('img');
150
+ img.src = url;
151
+ responseContainer.appendChild(img);
152
+ } else if (response.type.startsWith('video/')) {
153
+ const video = document.createElement('video');
154
+ video.src = url;
155
+ video.controls = true;
156
+ responseContainer.appendChild(video);
157
+ } else {
158
+ displayMessage('Unsupported file type received.', 'system');
159
+ }
160
+ } else {
161
+ displayMessage('Invalid response received.', 'system');
162
+ }
163
+ }
164
+
165
+ chatForm.addEventListener('submit', async (event) => {
166
+ event.preventDefault();
167
+ const question = document.getElementById('question').value;
168
+ displayMessage(question, 'user');
169
+ const response = await fetch('/ask', {
170
+ method: 'POST',
171
+ headers: {
172
+ 'Content-Type': 'application/x-www-form-urlencoded'
173
+ },
174
+ body: `question=${question}`
175
+ }).then(res => res.text());
176
+ displayMessage(response, 'system');
177
+ });
178
+
179
+ audioForm.addEventListener('submit', async (event) => {
180
+ event.preventDefault();
181
+ const audioFile = document.getElementById('audio-file').files[0];
182
+ const formData = new FormData();
183
+ formData.append('file', audioFile);
184
+ const response = await fetch('/upload-audio', {
185
+ method: 'POST',
186
+ body: formData
187
+ }).then(res => res.json());
188
+ displayMessage(response.transcription, 'user');
189
+ displayMessage(response.response, 'system');
190
+ const audio = new Audio(response.tts_audio);
191
+ audio.play();
192
+ });
193
+
194
+ imageForm.addEventListener('submit', async (event) => {
195
+ event.preventDefault();
196
+ const imagePrompt = document.getElementById('image-prompt').value;
197
+ displayMessage(`Generating image for: ${imagePrompt}`, 'user');
198
+ const response = await fetch('/generate-image', {
199
+ method: 'POST',
200
+ headers: {
201
+ 'Content-Type': 'application/x-www-form-urlencoded'
202
+ },
203
+ body: `text_prompt=${imagePrompt}`
204
+ }).then(res => res.blob());
205
+ displayResponse(response);
206
+ });
207
+
208
+ videoForm.addEventListener('submit', async (event) => {
209
+ event.preventDefault();
210
+ const videoPrompt = document.getElementById('video-prompt').value;
211
+ displayMessage(`Generating video for: ${videoPrompt}`, 'user');
212
+ const response = await fetch('/generate-video', {
213
+ method: 'POST',
214
+ headers: {
215
+ 'Content-Type': 'application/x-www-form-urlencoded'
216
+ },
217
+ body: `text_prompt=${videoPrompt}`
218
+ }).then(res => res.blob());
219
+ displayResponse(response);
220
+ });
221
+
222
+ summarizeTextForm.addEventListener('submit', async (event) => {
223
+ event.preventDefault();
224
+ const textToSummarize = document.getElementById('text-to-summarize').value;
225
+ displayMessage(`Summarizing text: ${textToSummarize}`, 'user');
226
+ const response = await fetch('/summarize-text', {
227
+ method: 'POST',
228
+ headers: {
229
+ 'Content-Type': 'application/x-www-form-urlencoded'
230
+ },
231
+ body: `text=${textToSummarize}`
232
+ }).then(res => res.text());
233
+ displayMessage(response, 'system');
234
+ });
235
+
236
+ summarizeFileForm.addEventListener('submit', async (event) => {
237
+ event.preventDefault();
238
+ const fileToSummarize = document.getElementById('file-to-summarize').files[0];
239
+ const formData = new FormData();
240
+ formData.append('file', fileToSummarize);
241
+ const response = await fetch('/summarize-file', {
242
+ method: 'POST',
243
+ body: formData
244
+ }).then(res => res.text());
245
+ displayMessage(response, 'system');
246
+ });
247
+
248
+ function getChatMessages() {
249
+ fetch("/messages")
250
+ .then(response => response.text())
251
+ .then(data => {
252
+ chatHistory.innerHTML = data;
253
+ });
254
+ }
255
+
256
+ function getContentPreview() {
257
+ fetch("/content-preview")
258
+ .then(response => response.text())
259
+ .then(data => {
260
+ contentPreview.innerHTML = data;
261
+ });
262
+ }
263
+
264
+ setInterval(getChatMessages, 5000);
265
+ setInterval(getContentPreview, 5000);
266
+ </script>
267
+ </body>
268
+ </html>
requirements.txt ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ fastapi
2
+ pydantic
3
+ uvicorn
4
+ requests
5
+ Pillow
6
+ python-dotenv
7
+ scikit-learn
8
+ google-generativeai
9
+ starlette
10
+ google-cloud-speech
11
+ google-cloud-texttospeech
12
+ fastapi
13
+ uvicorn
14
+ requests
15
+ pillow
16
+ moviepy
17
+ transformers
18
+ pydantic
19
+ google-cloud-storage
20
+ nltk
21
+ genai
22
+ torch
23
+ fastapi
24
+ uvicorn
25
+ scikit-learn
26
+ google-cloud-storage
27
+ google-cloud-speech
28
+ google-cloud-texttospeech
29
+ transformers
30
+ requests
31
+ google-generativeai
32
+ google-cloud-aiplatform
33
+ moviepy
34
+ Pillow
35
+ python-dotenv
36
+ gradio