freddyaboulton HF staff commited on
Commit
fb9623a
Β·
verified Β·
1 Parent(s): f0ab4ba

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +174 -19
index.html CHANGED
@@ -1,19 +1,174 @@
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">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Compliment Bot πŸ’–</title>
7
+ <!-- <script src="https://cdn.jsdelivr.net/npm/@gradio/[email protected]/dist/index.min.js"></script> -->
8
+ <style>
9
+ body {
10
+ font-family: Arial, sans-serif;
11
+ display: flex;
12
+ justify-content: center;
13
+ align-items: center;
14
+ height: 100vh;
15
+ margin: 0;
16
+ background-color: #f0f0f0;
17
+ }
18
+ .container {
19
+ text-align: center;
20
+ background-color: white;
21
+ padding: 20px;
22
+ border-radius: 10px;
23
+ box-shadow: 0 0 10px rgba(0,0,0,0.1);
24
+ max-width: 400px;
25
+ width: 100%;
26
+ }
27
+ #headshot {
28
+ max-width: 300px;
29
+ max-height: 300px;
30
+ margin: 20px auto;
31
+ display: block;
32
+ }
33
+ #compliment {
34
+ font-size: 18px;
35
+ font-weight: bold;
36
+ color: #4a4a4a;
37
+ min-height: 50px;
38
+ }
39
+ .loader {
40
+ border: 5px solid #f3f3f3;
41
+ border-top: 5px solid #3498db;
42
+ border-radius: 50%;
43
+ width: 30px;
44
+ height: 30px;
45
+ animation: spin 1s linear infinite;
46
+ margin: 20px auto;
47
+ display: none;
48
+ }
49
+ @keyframes spin {
50
+ 0% { transform: rotate(0deg); }
51
+ 100% { transform: rotate(360deg); }
52
+ }
53
+ #uploadButton {
54
+ background-color: #4CAF50;
55
+ border: none;
56
+ color: white;
57
+ padding: 10px 20px;
58
+ text-align: center;
59
+ text-decoration: none;
60
+ display: inline-block;
61
+ font-size: 16px;
62
+ margin: 4px 2px;
63
+ cursor: pointer;
64
+ border-radius: 5px;
65
+ }
66
+ </style>
67
+ </head>
68
+ <body>
69
+ <div class="container">
70
+ <h1> Compliment Bot πŸ’–</h1>
71
+ <input type="file" id="fileInput" accept="image/*" style="display: none;">
72
+ <button id="uploadButton">Upload New Headshot</button>
73
+ <br><br>
74
+ <img id="headshot" src="" alt="Your headshot" style="display:none;">
75
+ <div class="loader" id="loader"></div>
76
+ <p id="compliment"></p>
77
+ </div>
78
+
79
+ <script>
80
+ const fileInput = document.getElementById('fileInput');
81
+ const uploadButton = document.getElementById('uploadButton');
82
+ const headshot = document.getElementById('headshot');
83
+ const compliment = document.getElementById('compliment');
84
+ const loader = document.getElementById('loader');
85
+
86
+ const SYSTEM_PROMPT = `
87
+ You are helpful assistant that gives the best compliments to people.
88
+ You will be given a caption of someone's headshot.
89
+ Based on that caption, provide a one sentence compliment to the person in the image.
90
+ Make sure you compliment the person in the image and not any objects or scenery.
91
+ Do NOT include any hashtags in your compliment or phrases like (emojis: dog, smiling face with heart-eyes, sun).
92
+
93
+ Good Example:
94
+
95
+ Caption: a front view of a man who is smiling, there is a lighthouse in the background, there is a grassy area on the left that is green and curved. in the distance you can see the ocean and the shore. there is a grey and cloudy sky above the lighthouse and the trees.
96
+ Compliment: Your smile is as bright as a lighthouse, lighting up the world around you. 🌟
97
+
98
+ Good Example:
99
+
100
+ Caption: in a close-up, a blonde woman with short, wavy hair, is the focal point of the image. she's dressed in a dark brown turtleneck sweater, paired with a black hat and a black suit jacket. her lips are a vibrant red, and her eyes are a deep brown. in the background, a man with a black hat and a white shirt is visible.
101
+ Compliment: You are the epitome of elegance and grace, with a style that is as timeless as your beauty. πŸ’ƒπŸŽ©
102
+
103
+ Bad Example:
104
+
105
+ Caption: a front view of a man who is smiling, there is a lighthouse in the background, there is a grassy area on the left that is green and curved. in the distance you can see the ocean and the shore. there is a grey and cloudy sky above the lighthouse and the trees.
106
+ Compliment: You are standing in front of a lovely lighthouse!
107
+
108
+ Bad Example:
109
+
110
+ Caption: a long-haired, reddish-brown dog is captured in a close-up, eye-level shot, sitting on a dirt path in front of a lake. the dog's tongue is partially visible, and it's mouth is slightly ajar, revealing a white tooth. the dog's eyes are a striking brown, and it's tongue is a vibrant orange.
111
+ Compliment: Your furry friend's smile is contagious, from their sparkling brown eyes to their vibrant orange tongue peeking out! πŸΆπŸ€©πŸŒ… (emojis: dog, smiling face with heart-eyes, sun)
112
+ `
113
+
114
+ uploadButton.addEventListener('click', function() {
115
+ fileInput.click();
116
+ });
117
+
118
+ fileInput.addEventListener('change', function(e) {
119
+ const file = e.target.files[0];
120
+ if (file) {
121
+ const reader = new FileReader();
122
+ reader.onload = function(event) {
123
+ headshot.src = event.target.result;
124
+ headshot.style.display = 'block';
125
+ generateCompliment(file);
126
+ }
127
+ reader.readAsDataURL(file);
128
+ }
129
+ });
130
+
131
+ async function generateCompliment(file) {
132
+ compliment.textContent = '';
133
+ loader.style.display = 'block';
134
+
135
+ try {
136
+ const client_lib = await import("https://cdn.jsdelivr.net/npm/@gradio/[email protected]/dist/index.min.js");
137
+ const Client = client_lib.Client;
138
+ const handle_file = client_lib.handle_file;
139
+ const captioning_space = await Client.connect("gokaygokay/SD3-Long-Captioner");
140
+ const llm_space = await Client.connect("hysts/zephyr-7b");
141
+
142
+ const caption = await captioning_space.predict("/create_captions_rich", { image: file });
143
+
144
+
145
+ console.info("Caption", caption.data);
146
+
147
+ const submission = llm_space.submit("/chat", {
148
+ system_prompt: SYSTEM_PROMPT,
149
+ message: `Caption: ${caption.data}\nCompliment: `,
150
+ max_new_tokens: 1024,
151
+ temperature: 0.7,
152
+ top_p: 0.95,
153
+ top_k: 50,
154
+ repetition_penalty: 1,
155
+ }
156
+ )
157
+
158
+ for await (const msg of submission) {
159
+ loader.style.display = 'none';
160
+ if (msg.type === "data") {
161
+ console.log("msg.data", msg.data);
162
+ compliment.textContent = msg.data[0]
163
+ }
164
+ }
165
+ } catch (error) {
166
+ console.error('Error:', error);
167
+ loader.style.display = 'none';
168
+ compliment.textContent = "Oops! We couldn't generate a compliment. You're still awesome though!"
169
+ }
170
+
171
+ }
172
+ </script>
173
+ </body>
174
+ </html>