Spaces:
Sleeping
Sleeping
VictorSanh
commited on
Commit
•
34db65e
1
Parent(s):
1056de2
fixes
Browse files
app.py
CHANGED
@@ -21,7 +21,7 @@ PROCESSOR = AutoProcessor.from_pretrained(
|
|
21 |
token=API_TOKEN,
|
22 |
)
|
23 |
MODEL = AutoModelForCausalLM.from_pretrained(
|
24 |
-
"HuggingFaceM4/img2html",
|
25 |
token=API_TOKEN,
|
26 |
trust_remote_code=True,
|
27 |
torch_dtype=torch.bfloat16,
|
@@ -123,138 +123,27 @@ def model_inference(
|
|
123 |
|
124 |
inputs = PROCESSOR.tokenizer(
|
125 |
f"{BOS_TOKEN}<fake_token_around_image>{'<image>' * image_seq_len}<fake_token_around_image>",
|
126 |
-
return_tensors="pt"
|
|
|
127 |
)
|
128 |
inputs["pixel_values"] = PROCESSOR.image_processor(
|
129 |
[image],
|
130 |
transform=custom_transform
|
131 |
)
|
132 |
-
inputs = {
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
margin: 0;
|
147 |
-
padding: 0;
|
148 |
-
background-color: #f4f4f4;
|
149 |
-
}
|
150 |
-
|
151 |
-
header {
|
152 |
-
background-color: #333;
|
153 |
-
color: #fff;
|
154 |
-
padding: 1em;
|
155 |
-
text-align: center;
|
156 |
-
}
|
157 |
-
|
158 |
-
nav {
|
159 |
-
background-color: #555;
|
160 |
-
color: #fff;
|
161 |
-
padding: 0.5em;
|
162 |
-
text-align: center;
|
163 |
-
}
|
164 |
-
|
165 |
-
nav a {
|
166 |
-
color: #fff;
|
167 |
-
text-decoration: none;
|
168 |
-
padding: 0.5em 1em;
|
169 |
-
margin: 0 1em;
|
170 |
-
}
|
171 |
-
|
172 |
-
section {
|
173 |
-
padding: 2em;
|
174 |
-
}
|
175 |
-
|
176 |
-
h2 {
|
177 |
-
color: #333;
|
178 |
-
}
|
179 |
-
|
180 |
-
.car-container {
|
181 |
-
display: flex;
|
182 |
-
flex-wrap: wrap;
|
183 |
-
justify-content: space-around;
|
184 |
-
}
|
185 |
-
|
186 |
-
.car-card {
|
187 |
-
width: 300px;
|
188 |
-
margin: 1em;
|
189 |
-
border: 1px solid #ddd;
|
190 |
-
border-radius: 5px;
|
191 |
-
overflow: hidden;
|
192 |
-
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
193 |
-
}
|
194 |
-
|
195 |
-
.car-image {
|
196 |
-
width: 100%;
|
197 |
-
height: 150px;
|
198 |
-
object-fit: cover;
|
199 |
-
}
|
200 |
-
|
201 |
-
.car-details {
|
202 |
-
padding: 1em;
|
203 |
-
}
|
204 |
-
|
205 |
-
footer {
|
206 |
-
background-color: #333;
|
207 |
-
color: #fff;
|
208 |
-
text-align: center;
|
209 |
-
padding: 1em;
|
210 |
-
position: fixed;
|
211 |
-
bottom: 0;
|
212 |
-
width: 100%;
|
213 |
-
}
|
214 |
-
</style>
|
215 |
-
</head>
|
216 |
-
<body>
|
217 |
-
|
218 |
-
<header>
|
219 |
-
<h1>XYZ Car Company</h1>
|
220 |
-
</header>
|
221 |
-
|
222 |
-
<nav>
|
223 |
-
<a href="#">Home</a>
|
224 |
-
<a href="#">Models</a>
|
225 |
-
<a href="#">About Us</a>
|
226 |
-
<a href="#">Contact</a>
|
227 |
-
</nav>
|
228 |
-
|
229 |
-
<section>
|
230 |
-
<h2>Our Cars</h2>
|
231 |
-
<div class="car-container">
|
232 |
-
<div class="car-card">
|
233 |
-
<img src="car1.jpg" alt="Car 1" class="car-image">
|
234 |
-
<div class="car-details">
|
235 |
-
<h3>Model A</h3>
|
236 |
-
<p>Description of Model A.</p>
|
237 |
-
</div>
|
238 |
-
</div>
|
239 |
-
|
240 |
-
<div class="car-card">
|
241 |
-
<img src="car2.jpg" alt="Car 2" class="car-image">
|
242 |
-
<div class="car-details">
|
243 |
-
<h3>Model B</h3>
|
244 |
-
<p>Description of Model B.</p>
|
245 |
-
</div>
|
246 |
-
</div>
|
247 |
-
|
248 |
-
<!-- Add more car cards as needed -->
|
249 |
-
</div>
|
250 |
-
</section>
|
251 |
-
|
252 |
-
<footer>
|
253 |
-
© 2024 XYZ Car Company. All rights reserved.
|
254 |
-
</footer>
|
255 |
-
|
256 |
-
</body>
|
257 |
-
</html>"""
|
258 |
rendered_page = render_webpage(generated_text)
|
259 |
return generated_text, rendered_page
|
260 |
|
|
|
21 |
token=API_TOKEN,
|
22 |
)
|
23 |
MODEL = AutoModelForCausalLM.from_pretrained(
|
24 |
+
"HuggingFaceM4/img2html",
|
25 |
token=API_TOKEN,
|
26 |
trust_remote_code=True,
|
27 |
torch_dtype=torch.bfloat16,
|
|
|
123 |
|
124 |
inputs = PROCESSOR.tokenizer(
|
125 |
f"{BOS_TOKEN}<fake_token_around_image>{'<image>' * image_seq_len}<fake_token_around_image>",
|
126 |
+
return_tensors="pt",
|
127 |
+
add_special_tokens=False,
|
128 |
)
|
129 |
inputs["pixel_values"] = PROCESSOR.image_processor(
|
130 |
[image],
|
131 |
transform=custom_transform
|
132 |
)
|
133 |
+
inputs = {
|
134 |
+
k: v.to(DEVICE)
|
135 |
+
for k, v in inputs.items()
|
136 |
+
}
|
137 |
+
generated_ids = MODEL.generate(
|
138 |
+
**inputs,
|
139 |
+
bad_words_ids=BAD_WORDS_IDS,
|
140 |
+
max_length=4096
|
141 |
+
)
|
142 |
+
generated_text = PROCESSOR.batch_decode(
|
143 |
+
generated_ids,
|
144 |
+
skip_special_tokens=True
|
145 |
+
)[0]
|
146 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
147 |
rendered_page = render_webpage(generated_text)
|
148 |
return generated_text, rendered_page
|
149 |
|