Spaces:
Running
Running
scrolling bug maybe from margin/padding top?
Browse files- components/Header.js +1 -1
- pages/index.js +143 -145
components/Header.js
CHANGED
|
@@ -3,7 +3,7 @@ import { Github, Info } from 'lucide-react';
|
|
| 3 |
|
| 4 |
const Header = () => {
|
| 5 |
return (
|
| 6 |
-
<div className="
|
| 7 |
<div className="w-full flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4 sm:gap-0">
|
| 8 |
<div className="flex items-center gap-2 text-base">
|
| 9 |
<span className="text-black font-bold text-lg">Image to Code</span>
|
|
|
|
| 3 |
|
| 4 |
const Header = () => {
|
| 5 |
return (
|
| 6 |
+
<div className="sticky top-0 w-full bg-white p-4 z-50 ">
|
| 7 |
<div className="w-full flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4 sm:gap-0">
|
| 8 |
<div className="flex items-center gap-2 text-base">
|
| 9 |
<span className="text-black font-bold text-lg">Image to Code</span>
|
pages/index.js
CHANGED
|
@@ -290,171 +290,169 @@ export default function Home() {
|
|
| 290 |
<>
|
| 291 |
<Head>
|
| 292 |
<title>Image to Code</title>
|
| 293 |
-
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1
|
| 294 |
</Head>
|
| 295 |
-
<div className="
|
| 296 |
<Header />
|
| 297 |
<ErrorModal
|
| 298 |
isOpen={showErrorModal}
|
| 299 |
onClose={() => setShowErrorModal(false)}
|
| 300 |
/>
|
| 301 |
|
| 302 |
-
<
|
| 303 |
-
<div className=
|
| 304 |
-
<div className={`
|
| 305 |
-
<
|
| 306 |
-
<
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
<div className="
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
className={`flex-shrink-0 w-14 h-14 bg-white rounded-lg hover:scale-110 transition-all ${selectedSample === image ? 'border-blue-500 ring-2 ring-blue-200' : 'border-gray-300'
|
| 338 |
-
}`}
|
| 339 |
-
>
|
| 340 |
-
<img
|
| 341 |
-
src={`/samples/${image}`}
|
| 342 |
-
alt={image}
|
| 343 |
-
className="w-full h-full object-cover rounded-lg"
|
| 344 |
-
/>
|
| 345 |
-
</button>
|
| 346 |
-
))}
|
| 347 |
-
</div>
|
| 348 |
-
</div>
|
| 349 |
-
</section>
|
| 350 |
-
<section className="mt-4 space-y-4 bg-gray-100 rounded-2xl p-4">
|
| 351 |
-
<div>
|
| 352 |
-
<button
|
| 353 |
-
type="button"
|
| 354 |
-
onClick={() => setShowSamples(!showSamples)}
|
| 355 |
-
className="flex items-center gap-2 text-sm text-gray-600 hover:text-gray-800 transition-colors"
|
| 356 |
-
>
|
| 357 |
-
{/* <Settings size={16} /> */}
|
| 358 |
-
<span className="font-bold">Advanced</span>
|
| 359 |
-
<ChevronDown
|
| 360 |
-
size={16}
|
| 361 |
-
className={`transform transition-transform ${showSamples ? 'rotate-180' : ''
|
| 362 |
}`}
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
<Layers size={14} className="text-gray-600" />
|
| 372 |
-
<label htmlFor="concurrent-requests" className="text-sm font-medium text-gray-700">
|
| 373 |
-
Concurrent Requests: {concurrentRequests}
|
| 374 |
-
</label>
|
| 375 |
-
</div>
|
| 376 |
-
<input
|
| 377 |
-
id="concurrent-requests"
|
| 378 |
-
type="range"
|
| 379 |
-
min="1"
|
| 380 |
-
max="10"
|
| 381 |
-
value={concurrentRequests}
|
| 382 |
-
onChange={(e) => setConcurrentRequests(Number(e.target.value))}
|
| 383 |
-
className="w-1/2"
|
| 384 |
-
/>
|
| 385 |
-
</div>
|
| 386 |
-
|
| 387 |
-
<button
|
| 388 |
-
type="button"
|
| 389 |
-
onClick={() => setShowPrompt(!showPrompt)}
|
| 390 |
-
className="flex items-center gap-2 text-sm text-gray-600 hover:text-gray-800 transition-colors"
|
| 391 |
-
>
|
| 392 |
-
<Pen size={14} />
|
| 393 |
-
<span>Edit System Prompt</span>
|
| 394 |
-
<ChevronDown
|
| 395 |
-
size={16}
|
| 396 |
-
className={`transform transition-transform ${showPrompt ? 'rotate-180' : ''}`}
|
| 397 |
-
/>
|
| 398 |
-
</button>
|
| 399 |
-
|
| 400 |
-
{showPrompt && (
|
| 401 |
-
<textarea
|
| 402 |
-
value={prompt}
|
| 403 |
-
onChange={(e) => setPrompt(e.target.value)}
|
| 404 |
-
className="w-full h-64 p-2 border rounded-lg font-mono text-sm mt-2 bg-white text-gray-900"
|
| 405 |
-
placeholder="Enter your prompt here..."
|
| 406 |
-
/>
|
| 407 |
-
)}
|
| 408 |
-
</div>
|
| 409 |
-
</div>
|
| 410 |
-
)}
|
| 411 |
</div>
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
|
|
|
|
| 415 |
<button
|
| 416 |
type="button"
|
| 417 |
-
onClick={
|
| 418 |
-
className="
|
| 419 |
-
hover:bg-gray-900 transition-colors w-full disabled:bg-gray-300 disabled:cursor-not-allowed
|
| 420 |
-
flex items-center justify-center gap-2 font-bold"
|
| 421 |
-
disabled={!imageBase64 || loading}
|
| 422 |
>
|
| 423 |
-
{/* <
|
| 424 |
-
<span
|
| 425 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 426 |
</button>
|
| 427 |
-
</section>
|
| 428 |
-
</div>
|
| 429 |
|
| 430 |
-
|
| 431 |
-
|
| 432 |
-
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
|
| 437 |
-
|
| 438 |
-
|
| 439 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 440 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 441 |
</div>
|
| 442 |
-
|
| 443 |
-
) : (
|
| 444 |
-
outputs.map((output) => (
|
| 445 |
-
<CodePreview
|
| 446 |
-
key={output.id}
|
| 447 |
-
output={output}
|
| 448 |
-
onCodeChange={handleCodeChange}
|
| 449 |
-
fullResponse={output.fullResponse}
|
| 450 |
-
/>
|
| 451 |
-
))
|
| 452 |
)}
|
| 453 |
</div>
|
| 454 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 455 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 456 |
</div>
|
| 457 |
-
</
|
| 458 |
</div>
|
| 459 |
</>
|
| 460 |
);
|
|
|
|
| 290 |
<>
|
| 291 |
<Head>
|
| 292 |
<title>Image to Code</title>
|
| 293 |
+
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
|
| 294 |
</Head>
|
| 295 |
+
<div className="bg-white">
|
| 296 |
<Header />
|
| 297 |
<ErrorModal
|
| 298 |
isOpen={showErrorModal}
|
| 299 |
onClose={() => setShowErrorModal(false)}
|
| 300 |
/>
|
| 301 |
|
| 302 |
+
<div className="w-full">
|
| 303 |
+
<div className={`flex flex-col md:flex-row gap-4 max-w-6xl mx-auto pb-20 ${!hasStartedGenerating ? 'justify-center' : ''}`}>
|
| 304 |
+
<div className={`w-full md:flex-1 py-4 px-3 ${!hasStartedGenerating ? 'md:max-w-2xl mx-auto' : ''}`}>
|
| 305 |
+
<section className="flex flex-col bg-gray-100 rounded-2xl p-4">
|
| 306 |
+
<div
|
| 307 |
+
{...getRootProps()}
|
| 308 |
+
className={`border-2 border-dashed bg-gray-100 rounded-2xl m-4 min-h-96 h-fit flex
|
| 309 |
+
flex-col items-center justify-center cursor-pointer hover:border-gray-400 transition-colors ${imageBase64 ? 'border-none' : 'border-gray-300'}`}
|
| 310 |
+
>
|
| 311 |
+
<input {...getInputProps()} />
|
| 312 |
+
{imageBase64 ? (
|
| 313 |
+
<img
|
| 314 |
+
src={imageBase64}
|
| 315 |
+
alt="Uploaded"
|
| 316 |
+
className="max-h-full max-w-full object-contain rounded-2xl"
|
| 317 |
+
/>
|
| 318 |
+
) : (
|
| 319 |
+
<>
|
| 320 |
+
<Upload className="w-12 h-12 text-gray-400 mb-4" />
|
| 321 |
+
<p className="text-gray-400 text-center px-4">
|
| 322 |
+
{isDragActive
|
| 323 |
+
? "Drop the image here"
|
| 324 |
+
: "Drag & drop an image here, or click to select one"}
|
| 325 |
+
</p>
|
| 326 |
+
</>
|
| 327 |
+
)}
|
| 328 |
+
</div>
|
| 329 |
+
<div className="max-w-full mb-4">
|
| 330 |
+
<div className="flex overflow-x-auto gap-2 py-1 mx-4">
|
| 331 |
+
{SAMPLE_IMAGES.map((image) => (
|
| 332 |
+
<button
|
| 333 |
+
key={image}
|
| 334 |
+
type="button"
|
| 335 |
+
onClick={() => handleSampleSelect(image)}
|
| 336 |
+
className={`flex-shrink-0 w-14 h-14 bg-white rounded-lg hover:scale-110 transition-all ${selectedSample === image ? 'border-blue-500 ring-2 ring-blue-200' : 'border-gray-300'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 337 |
}`}
|
| 338 |
+
>
|
| 339 |
+
<img
|
| 340 |
+
src={`/samples/${image}`}
|
| 341 |
+
alt={image}
|
| 342 |
+
className="w-full h-full object-cover rounded-lg"
|
| 343 |
+
/>
|
| 344 |
+
</button>
|
| 345 |
+
))}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 346 |
</div>
|
| 347 |
+
</div>
|
| 348 |
+
</section>
|
| 349 |
+
<section className="mt-4 space-y-4 bg-gray-100 rounded-2xl p-4">
|
| 350 |
+
<div>
|
| 351 |
<button
|
| 352 |
type="button"
|
| 353 |
+
onClick={() => setShowSamples(!showSamples)}
|
| 354 |
+
className="flex items-center gap-2 text-sm text-gray-600 hover:text-gray-800 transition-colors"
|
|
|
|
|
|
|
|
|
|
| 355 |
>
|
| 356 |
+
{/* <Settings size={16} /> */}
|
| 357 |
+
<span className="font-bold">Advanced</span>
|
| 358 |
+
<ChevronDown
|
| 359 |
+
size={16}
|
| 360 |
+
className={`transform transition-transform ${showSamples ? 'rotate-180' : ''
|
| 361 |
+
}`}
|
| 362 |
+
/>
|
| 363 |
</button>
|
|
|
|
|
|
|
| 364 |
|
| 365 |
+
{showSamples && (
|
| 366 |
+
<div className="my-2 rounded-lg">
|
| 367 |
+
<div className="space-y-2">
|
| 368 |
+
<div className="flex items-center justify-between">
|
| 369 |
+
<div className="flex items-center gap-2">
|
| 370 |
+
<Layers size={14} className="text-gray-600" />
|
| 371 |
+
<label htmlFor="concurrent-requests" className="text-sm font-medium text-gray-700">
|
| 372 |
+
Concurrent Requests: {concurrentRequests}
|
| 373 |
+
</label>
|
| 374 |
+
</div>
|
| 375 |
+
<input
|
| 376 |
+
id="concurrent-requests"
|
| 377 |
+
type="range"
|
| 378 |
+
min="1"
|
| 379 |
+
max="10"
|
| 380 |
+
value={concurrentRequests}
|
| 381 |
+
onChange={(e) => setConcurrentRequests(Number(e.target.value))}
|
| 382 |
+
className="w-1/2"
|
| 383 |
+
/>
|
| 384 |
</div>
|
| 385 |
+
|
| 386 |
+
<button
|
| 387 |
+
type="button"
|
| 388 |
+
onClick={() => setShowPrompt(!showPrompt)}
|
| 389 |
+
className="flex items-center gap-2 text-sm text-gray-600 hover:text-gray-800 transition-colors"
|
| 390 |
+
>
|
| 391 |
+
<Pen size={14} />
|
| 392 |
+
<span>Edit System Prompt</span>
|
| 393 |
+
<ChevronDown
|
| 394 |
+
size={16}
|
| 395 |
+
className={`transform transition-transform ${showPrompt ? 'rotate-180' : ''}`}
|
| 396 |
+
/>
|
| 397 |
+
</button>
|
| 398 |
+
|
| 399 |
+
{showPrompt && (
|
| 400 |
+
<textarea
|
| 401 |
+
value={prompt}
|
| 402 |
+
onChange={(e) => setPrompt(e.target.value)}
|
| 403 |
+
className="w-full h-64 p-2 border rounded-lg font-mono text-sm mt-2 bg-white text-gray-900"
|
| 404 |
+
placeholder="Enter your prompt here..."
|
| 405 |
+
/>
|
| 406 |
+
)}
|
| 407 |
</div>
|
| 408 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 409 |
)}
|
| 410 |
</div>
|
| 411 |
+
|
| 412 |
+
</section>
|
| 413 |
+
<section className="mt-4">
|
| 414 |
+
<button
|
| 415 |
+
type="button"
|
| 416 |
+
onClick={generateCode}
|
| 417 |
+
className="px-4 py-4 bg-gray-800 text-white rounded-2xl mb-8
|
| 418 |
+
hover:bg-gray-900 transition-colors w-full disabled:bg-gray-300 disabled:cursor-not-allowed
|
| 419 |
+
flex items-center justify-center gap-2 font-bold"
|
| 420 |
+
disabled={!imageBase64 || loading}
|
| 421 |
+
>
|
| 422 |
+
{/* <Send size={16} className={loading ? 'opacity-50' : ''} /> */}
|
| 423 |
+
<span>{loading ? "Generating..." : `Generate ${concurrentRequests} Code Snippet${concurrentRequests > 1 ? 's' : ''}`}</span>
|
| 424 |
+
|
| 425 |
+
</button>
|
| 426 |
+
</section>
|
| 427 |
</div>
|
| 428 |
+
|
| 429 |
+
{hasStartedGenerating && (
|
| 430 |
+
<div className="w-full md:flex-1 py-4 md:py-20 px-3 animate-slide-in">
|
| 431 |
+
{loading ? (
|
| 432 |
+
// Loading skeletons for code previews
|
| 433 |
+
Array(concurrentRequests).fill().map((_, index) => (
|
| 434 |
+
<div key={`skeleton-preview-${Date.now()}-${index}`} className="mb-4 p-6 rounded-3xl bg-gray-100 animate-pulse">
|
| 435 |
+
<div className="w-full h-[500px] bg-gray-200 rounded-lg mb-4" />
|
| 436 |
+
<div className="flex justify-between items-center">
|
| 437 |
+
<div className="h-10 w-32 bg-gray-200 rounded-full" />
|
| 438 |
+
<div className="h-10 w-24 bg-gray-200 rounded-full" />
|
| 439 |
+
</div>
|
| 440 |
+
</div>
|
| 441 |
+
))
|
| 442 |
+
) : (
|
| 443 |
+
outputs.map((output) => (
|
| 444 |
+
<CodePreview
|
| 445 |
+
key={output.id}
|
| 446 |
+
output={output}
|
| 447 |
+
onCodeChange={handleCodeChange}
|
| 448 |
+
fullResponse={output.fullResponse}
|
| 449 |
+
/>
|
| 450 |
+
))
|
| 451 |
+
)}
|
| 452 |
+
</div>
|
| 453 |
+
)}
|
| 454 |
</div>
|
| 455 |
+
</div>
|
| 456 |
</div>
|
| 457 |
</>
|
| 458 |
);
|