nikravan commited on
Commit
7740882
·
verified ·
1 Parent(s): b2ecc55

یک سیستم chatbot شبیه chatgpt بساز

Browse files
Files changed (6) hide show
  1. README.md +8 -5
  2. components/footer.js +52 -0
  3. components/navbar.js +67 -0
  4. index.html +129 -19
  5. script.js +23 -0
  6. style.css +28 -18
README.md CHANGED
@@ -1,10 +1,13 @@
1
  ---
2
- title: Chatty Mcbotface
3
- emoji: 🚀
4
- colorFrom: gray
5
- colorTo: purple
6
  sdk: static
7
  pinned: false
 
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
1
  ---
2
+ title: Chatty McBotface 🤖
3
+ colorFrom: red
4
+ colorTo: blue
5
+ emoji: 🐳
6
  sdk: static
7
  pinned: false
8
+ tags:
9
+ - deepsite-v3
10
  ---
11
 
12
+ # Welcome to your new DeepSite project!
13
+ This project was created with [DeepSite](https://huggingface.co/deepsite).
components/footer.js ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ class CustomFooter extends HTMLElement {
2
+ connectedCallback() {
3
+ this.attachShadow({ mode: 'open' });
4
+ this.shadowRoot.innerHTML = `
5
+ <style>
6
+ footer {
7
+ background: #1a202c;
8
+ color: white;
9
+ padding: 2rem;
10
+ text-align: center;
11
+ margin-top: auto;
12
+ }
13
+ .footer-content {
14
+ max-width: 1200px;
15
+ margin: 0 auto;
16
+ display: flex;
17
+ flex-direction: column;
18
+ gap: 1rem;
19
+ }
20
+ .footer-links {
21
+ display: flex;
22
+ justify-content: center;
23
+ gap: 1.5rem;
24
+ margin-bottom: 1rem;
25
+ }
26
+ .footer-links a {
27
+ color: #a0aec0;
28
+ text-decoration: none;
29
+ transition: color 0.2s;
30
+ }
31
+ .footer-links a:hover {
32
+ color: white;
33
+ }
34
+ .copyright {
35
+ color: #718096;
36
+ font-size: 0.875rem;
37
+ }
38
+ </style>
39
+ <footer>
40
+ <div class="footer-content">
41
+ <div class="footer-links">
42
+ <a href="#">Privacy Policy</a>
43
+ <a href="#">Terms of Service</a>
44
+ <a href="#">Contact Us</a>
45
+ </div>
46
+ <p class="copyright">© 2023 Chatty McBotface. All rights reserved.</p>
47
+ </div>
48
+ </footer>
49
+ `;
50
+ }
51
+ }
52
+ customElements.define('custom-footer', CustomFooter);
components/navbar.js ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ class CustomNavbar extends HTMLElement {
2
+ connectedCallback() {
3
+ this.attachShadow({ mode: 'open' });
4
+ this.shadowRoot.innerHTML = `
5
+ <style>
6
+ nav {
7
+ background: linear-gradient(135deg, var(--primary-500, #6366f1) 0%, var(--secondary-500, #8b5cf6) 100%);
8
+ padding: 1rem 2rem;
9
+ display: flex;
10
+ justify-content: space-between;
11
+ align-items: center;
12
+ box-shadow: 0 2px 10px rgba(0,0,0,0.1);
13
+ }
14
+ .logo {
15
+ color: white;
16
+ font-weight: bold;
17
+ font-size: 1.25rem;
18
+ display: flex;
19
+ align-items: center;
20
+ gap: 0.5rem;
21
+ }
22
+ ul {
23
+ display: flex;
24
+ gap: 1.5rem;
25
+ list-style: none;
26
+ margin: 0;
27
+ padding: 0;
28
+ }
29
+ a {
30
+ color: white;
31
+ text-decoration: none;
32
+ transition: opacity 0.2s;
33
+ font-weight: 500;
34
+ display: flex;
35
+ align-items: center;
36
+ gap: 0.25rem;
37
+ }
38
+ a:hover {
39
+ opacity: 0.8;
40
+ }
41
+ @media (max-width: 640px) {
42
+ nav {
43
+ flex-direction: column;
44
+ gap: 1rem;
45
+ padding: 1rem;
46
+ }
47
+ ul {
48
+ width: 100%;
49
+ justify-content: space-around;
50
+ }
51
+ }
52
+ </style>
53
+ <nav>
54
+ <div class="logo">
55
+ <i data-feather="message-square"></i>
56
+ <span>Chatty McBotface</span>
57
+ </div>
58
+ <ul>
59
+ <li><a href="/"><i data-feather="home"></i> Home</a></li>
60
+ <li><a href="#"><i data-feather="info"></i> About</a></li>
61
+ <li><a href="#"><i data-feather="settings"></i> Settings</a></li>
62
+ </ul>
63
+ </nav>
64
+ `;
65
+ }
66
+ }
67
+ customElements.define('custom-navbar', CustomNavbar);
index.html CHANGED
@@ -1,19 +1,129 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en" class="h-full">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Chatty McBotface - AI Chatbot</title>
7
+ <link rel="stylesheet" href="style.css">
8
+ <script src="https://cdn.tailwindcss.com"></script>
9
+ <script src="https://unpkg.com/feather-icons"></script>
10
+ <script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
11
+ <script>
12
+ tailwind.config = {
13
+ theme: {
14
+ extend: {
15
+ colors: {
16
+ primary: {
17
+ 500: '#6366f1',
18
+ },
19
+ secondary: {
20
+ 500: '#8b5cf6',
21
+ }
22
+ }
23
+ }
24
+ }
25
+ }
26
+ </script>
27
+ </head>
28
+ <body class="bg-gray-100 h-full flex flex-col">
29
+ <custom-navbar></custom-navbar>
30
+
31
+ <main class="flex-1 container mx-auto px-4 py-8">
32
+ <div id="chat-container" class="bg-white rounded-lg shadow-lg h-[70vh] overflow-hidden flex flex-col">
33
+ <div class="bg-gradient-to-r from-primary-500 to-secondary-500 p-4 text-white">
34
+ <div class="flex items-center gap-3">
35
+ <div class="w-10 h-10 rounded-full bg-white/20 flex items-center justify-center">
36
+ <i data-feather="message-square"></i>
37
+ </div>
38
+ <h2 class="text-xl font-bold">Chatty McBotface</h2>
39
+ </div>
40
+ </div>
41
+
42
+ <div id="chat-messages" class="flex-1 overflow-y-auto p-4 space-y-4">
43
+ <!-- Messages will be inserted here -->
44
+ <div class="w-full flex justify-center">
45
+ <div class="bg-gray-100 rounded-lg p-4 max-w-[80%] text-center">
46
+ <p class="text-gray-600">Hi there! I'm your friendly AI assistant. How can I help you today?</p>
47
+ </div>
48
+ </div>
49
+ </div>
50
+
51
+ <div class="p-4 border-t border-gray-200">
52
+ <form id="chat-form" class="flex gap-2">
53
+ <input
54
+ type="text"
55
+ id="user-input"
56
+ placeholder="Type your message here..."
57
+ class="flex-1 border border-gray-300 rounded-lg px-4 py-2 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:border-transparent"
58
+ autocomplete="off"
59
+ >
60
+ <button
61
+ type="submit"
62
+ class="bg-primary-500 hover:bg-primary-600 text-white px-4 py-2 rounded-lg transition-colors flex items-center gap-2"
63
+ >
64
+ <i data-feather="send" class="w-4 h-4"></i>
65
+ <span>Send</span>
66
+ </button>
67
+ </form>
68
+ </div>
69
+ </div>
70
+ </main>
71
+
72
+ <custom-footer></custom-footer>
73
+
74
+ <script src="components/navbar.js"></script>
75
+ <script src="components/footer.js"></script>
76
+ <script src="script.js"></script>
77
+ <script>
78
+ feather.replace();
79
+
80
+ // Simple chatbot logic
81
+ document.getElementById('chat-form').addEventListener('submit', function(e) {
82
+ e.preventDefault();
83
+ const input = document.getElementById('user-input');
84
+ const message = input.value.trim();
85
+
86
+ if (message) {
87
+ // Add user message
88
+ addMessage(message, 'user');
89
+ input.value = '';
90
+
91
+ // Simulate bot thinking
92
+ setTimeout(() => {
93
+ const responses = [
94
+ "I understand what you're asking about!",
95
+ "That's an interesting question!",
96
+ "Let me think about that for a moment...",
97
+ "I've processed your request and here's what I found:",
98
+ "According to my knowledge base:"
99
+ ];
100
+ const botResponse = responses[Math.floor(Math.random() * responses.length)] +
101
+ " This is a simulated response. In a real implementation, this would connect to an AI API like OpenAI.";
102
+
103
+ addMessage(botResponse, 'bot');
104
+ }, 1000);
105
+ }
106
+ });
107
+
108
+ function addMessage(text, sender) {
109
+ const messagesContainer = document.getElementById('chat-messages');
110
+ const messageDiv = document.createElement('div');
111
+ messageDiv.className = `w-full flex ${sender === 'user' ? 'justify-end' : 'justify-start'}`;
112
+
113
+ const bubbleClass = sender === 'user'
114
+ ? 'bg-primary-500 text-white rounded-br-none'
115
+ : 'bg-gray-100 text-gray-800 rounded-bl-none';
116
+
117
+ messageDiv.innerHTML = `
118
+ <div class="max-w-[80%] rounded-lg p-4 ${bubbleClass}">
119
+ <p>${text}</p>
120
+ </div>
121
+ `;
122
+
123
+ messagesContainer.appendChild(messageDiv);
124
+ messagesContainer.scrollTop = messagesContainer.scrollHeight;
125
+ }
126
+ </script>
127
+ <script src="https://huggingface.co/deepsite/deepsite-badge.js"></script>
128
+ </body>
129
+ </html>
script.js ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Shared JavaScript functions
2
+ console.log('Chatty McBotface initialized');
3
+
4
+ // You could add API integration here in a real implementation
5
+ // For example:
6
+ /*
7
+ async function getBotResponse(message) {
8
+ const response = await fetch('https://api.openai.com/v1/chat/completions', {
9
+ method: 'POST',
10
+ headers: {
11
+ 'Content-Type': 'application/json',
12
+ 'Authorization': 'Bearer YOUR_API_KEY'
13
+ },
14
+ body: JSON.stringify({
15
+ model: "gpt-3.5-turbo",
16
+ messages: [{role: "user", content: message}]
17
+ })
18
+ });
19
+
20
+ const data = await response.json();
21
+ return data.choices[0].message.content;
22
+ }
23
+ */
style.css CHANGED
@@ -1,28 +1,38 @@
 
1
  body {
2
- padding: 2rem;
3
- font-family: -apple-system, BlinkMacSystemFont, "Arial", sans-serif;
4
  }
5
 
6
- h1 {
7
- font-size: 16px;
8
- margin-top: 0;
9
  }
10
 
11
- p {
12
- color: rgb(107, 114, 128);
13
- font-size: 15px;
14
- margin-bottom: 10px;
15
- margin-top: 5px;
16
  }
17
 
18
- .card {
19
- max-width: 620px;
20
- margin: 0 auto;
21
- padding: 16px;
22
- border: 1px solid lightgray;
23
- border-radius: 16px;
24
  }
25
 
26
- .card p:last-child {
27
- margin-bottom: 0;
 
28
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Custom styles */
2
  body {
3
+ font-family: 'Inter', sans-serif;
 
4
  }
5
 
6
+ /* Smooth scroll for chat messages */
7
+ #chat-messages {
8
+ scroll-behavior: smooth;
9
  }
10
 
11
+ /* Animation for new messages */
12
+ @keyframes fadeIn {
13
+ from { opacity: 0; transform: translateY(10px); }
14
+ to { opacity: 1; transform: translateY(0); }
 
15
  }
16
 
17
+ #chat-messages > div {
18
+ animation: fadeIn 0.3s ease-out;
 
 
 
 
19
  }
20
 
21
+ /* Custom scrollbar for chat */
22
+ #chat-messages::-webkit-scrollbar {
23
+ width: 8px;
24
  }
25
+
26
+ #chat-messages::-webkit-scrollbar-track {
27
+ background: #f1f1f1;
28
+ border-radius: 4px;
29
+ }
30
+
31
+ #chat-messages::-webkit-scrollbar-thumb {
32
+ background: #c1c1c1;
33
+ border-radius: 4px;
34
+ }
35
+
36
+ #chat-messages::-webkit-scrollbar-thumb:hover {
37
+ background: #a1a1a1;
38
+ }