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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
<html>
|
| 3 |
+
|
| 4 |
+
<head>
|
| 5 |
+
<meta charset="utf-8" />
|
| 6 |
+
<meta name="viewport" content="width=device-width" />
|
| 7 |
+
<title>My static Space</title>
|
| 8 |
+
<link href="https://cdn.jsdelivr.net/npm/daisyui@3.1.6/dist/full.css" rel="stylesheet" type="text/css" />
|
| 9 |
+
<script src="https://cdn.tailwindcss.com?plugins=forms,typography,aspect-ratio"></script>
|
| 10 |
+
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
|
| 11 |
+
<script src="https://cdn.jsdelivr.net/npm/alpinejs@2.8.2/dist/alpine.min.js" defer></script>
|
| 12 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.8/clipboard.min.js"></script>
|
| 13 |
+
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
|
| 14 |
+
</head>
|
| 15 |
+
|
| 16 |
+
<body class="bg-stone-100 dark:bg-gray-800 dark:text-white" x-data="app()">
|
| 17 |
+
<div class="flex flex-col md:flex-row" x-data="app()" x-init="init()">
|
| 18 |
+
|
| 19 |
+
<div class="hero rounded-3xl md:h-screen bg-stone-200 transition-[width] delay-150 ease-in-out w-full md:w-6/6"
|
| 20 |
+
:class="open ? 'w-full md:w-2/6' : 'w-full md:w-6/6'">
|
| 21 |
+
<!-- <div class="flex justify-between items-center mb-2" style="padding: 10px;margin-left: auto;margin-bottom: auto;">
|
| 22 |
+
|
| 23 |
+
<button id="toggleDarkMode" class="mt-4 bg-gray-700 text-white px-4 py-2 rounded-md">Toggle Dark Mode</button>
|
| 24 |
+
|
| 25 |
+
</div> -->
|
| 26 |
+
<div class="hero-content text-center">
|
| 27 |
+
<div class="flex flex-col w-full md:max-w-xl space-y-3 md:space-y-6">
|
| 28 |
+
<h1 class="font-bold text-stone-600 mb-1 md:mb-3 transition-all delay-150 ease-in-out text-2xl md:text-3xl lg:text-6xl"
|
| 29 |
+
:class="open
|
| 30 |
+
? 'text-2xl md:text-3xl lg:text-4xl'
|
| 31 |
+
: 'text-2xl md:text-3xl lg:text-6xl'">
|
| 32 |
+
Text To Code
|
| 33 |
+
</h1>
|
| 34 |
+
<div class="py-1 md:py-2 space-y-2 md:space-y-3 text-stone-600 transition-all delay-150 ease-in-out text-lg lg:text-xl"
|
| 35 |
+
:class="open
|
| 36 |
+
? 'text-lg lg:text-xl'
|
| 37 |
+
: 'text-lg lg:text-xl'">
|
| 38 |
+
<p>A space to generate tiny web apps.</p>
|
| 39 |
+
<p>In case of hallucination try generating again 🎲</p>
|
| 40 |
+
</div>
|
| 41 |
+
|
| 42 |
+
<div x-show="openModal" @click.away="openModal = false" class=" fixed inset-0 z-50 overflow-auto bg-smoke-light flex items-center justify-center">
|
| 43 |
+
<div x-show="openModal" class="bg-gray-400 p-6 rounded shadow-md">
|
| 44 |
+
<h2 class="text-lg font-semibold mb-4">Choose Model</h2>
|
| 45 |
+
<div>
|
| 46 |
+
<button @click="selectModel('tiiuae/falcon-7b-instruct', 'https://about.fb.com/news/2023/08/code-llama-ai-for-coding')">tiiuae/falcon-7b-instruct</button><br>
|
| 47 |
+
<button @click="selectModel('mistralai/Mistral-7B-Instruct-v0.1', 'https://mistral.ai/news/announcing-mistral-7b')">models/mistralai/Mistral-7B-Instruct-v0.1</button>
|
| 48 |
+
</div>
|
| 49 |
+
</div>
|
| 50 |
+
</div>
|
| 51 |
+
<form @submit.prevent="generateCode">
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
<div class="lg:col-span-2 p-2"> <div class="overflow-hidden rounded-xl border border-gray-400"><div class="flex p-3"><div><div class="flex p-1 text-sm text-gray-600 ">Current Model</div> <div class="font-semibold text-black" id="ModelName">codellama/CodeLlama-34b-Instruct-hf</div></div> <button type="button" @click="openModal = true" class="btn ml-auto flex h-7 w-7 self-start rounded-full bg-gray-100 p-1 text-xs hover:bg-gray-100 dark:border-gray-600 dark:bg-gray-800 dark:hover:bg-gray-600" ><svg viewBox="0 0 16 16" width="1.2em" height="1.2em"><path fill="currentColor" d="M9.405 1.05c-.413-1.4-2.397-1.4-2.81 0l-.1.34a1.464 1.464 0 0 1-2.105.872l-.31-.17c-1.283-.698-2.686.705-1.987 1.987l.169.311c.446.82.023 1.841-.872 2.105l-.34.1c-1.4.413-1.4 2.397 0 2.81l.34.1a1.464 1.464 0 0 1 .872 2.105l-.17.31c-.698 1.283.705 2.686 1.987 1.987l.311-.169a1.464 1.464 0 0 1 2.105.872l.1.34c.413 1.4 2.397 1.4 2.81 0l.1-.34a1.464 1.464 0 0 1 2.105-.872l.31.17c1.283.698 2.686-.705 1.987-1.987l-.169-.311a1.464 1.464 0 0 1 .872-2.105l.34-.1c1.4-.413 1.4-2.397 0-2.81l-.34-.1a1.464 1.464 0 0 1-.872-2.105l.17-.31c.698-1.283-.705-2.686-1.987-1.987l-.311.169a1.464 1.464 0 0 1-2.105-.872l-.1-.34zM8 10.93a2.929 2.929 0 1 1 0-5.86a2.929 2.929 0 0 1 0 5.858z"></path></svg></button></div> <div class="flex items-center gap-5 rounded-xl bg-gray-300 px-3 py-2 text-xs sm:text-sm text-gray-600 "><a id="PageModel" :href="PageModel" target="_blank" rel="noreferrer" class="flex items-center hover:underline"><svg viewBox="0 0 32 32" width="1.2em" height="1.2em" class="mr-1.5 shrink-0 text-xs text-gray-400"><path fill="currentColor" d="M10 6v2h12.59L6 24.59L7.41 26L24 9.41V22h2V6H10z"></path></svg>
|
| 55 |
+
Model
|
| 56 |
+
<div class="max-sm:hidden"> page</div></a> <a href="https://about.fb.com/news/2023/08/code-llama-ai-for-coding/" target="_blank" class="ml-auto flex items-center hover:underline" rel="noreferrer"><svg viewBox="0 0 32 32" width="1.2em" height="1.2em" class="mr-1.5 shrink-0 text-xs text-gray-400"><path fill="currentColor" d="M16 2a14 14 0 1 0 14 14A14.016 14.016 0 0 0 16 2Zm5 3.106a12.014 12.014 0 0 1 2.916 1.899L23.503 8H21Zm-7.622 22.597A11.976 11.976 0 0 1 8.116 6.976L9.465 9h3.342l-1.5 4H7.28l-1.382 4.148L8.465 21h5l1.432 2.147ZM16 28c-.203 0-.402-.02-.603-.03l1.397-4.19a1.988 1.988 0 0 0-.233-1.741l-1.432-2.148A1.996 1.996 0 0 0 13.465 19h-3.93l-1.432-2.148L8.721 15H11v2h2v-2.819l2.936-7.83l-1.872-.702L13.557 7h-3.022l-.807-1.21A11.794 11.794 0 0 1 19 4.394V8a2.002 2.002 0 0 0 2 2h2.586A1.986 1.986 0 0 0 25 9.414l.14-.14l.282-.68A11.981 11.981 0 0 1 27.3 12h-4.701a1.993 1.993 0 0 0-1.972 1.665l-.597 3.441a1.99 1.99 0 0 0 .991 2.086l2.165 1.464l1.458 3.646A11.958 11.958 0 0 1 16 28Zm8.815-8.656L22.1 17.509l-.1-.06l.599-3.449h5.22a11.743 11.743 0 0 1-1.744 8.495Z"></path></svg>
|
| 57 |
+
Website</a></div></div></div>
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
<div class="mb-4 w-full max-w-3xl rounded-lg bg-slate-200">
|
| 62 |
+
<div class="rounded-lg rounded-b-none border border-slate-300 bg-slate-50 px-2 py-2">
|
| 63 |
+
<label for="prompt-input" class="sr-only">Describe your web app</label>
|
| 64 |
+
<textarea id="prompt-input" rows="4"
|
| 65 |
+
class="w-full border-0 bg-slate-50 px-0 text-base text-slate-900 focus:outline-none "
|
| 66 |
+
placeholder="Describe your web app" required></textarea>
|
| 67 |
+
</div>
|
| 68 |
+
<div class="ml-2 flex items-center py-2">
|
| 69 |
+
<div>
|
| 70 |
+
<button type="submit"
|
| 71 |
+
x-bind:class="{ 'bg-blue-600': !loading, 'bg-gray-400 cursor-not-allowed': loading }"
|
| 72 |
+
x-bind:disabled="loading"
|
| 73 |
+
class="inline-flex items-center gap-x-2 rounded-lg px-4 py-2.5 text-center text-base font-medium text-slate-50 hover:bg-blue-800 focus:ring-4 focus:ring-blue-200 dark:focus:ring-blue-900">
|
| 74 |
+
<span x-show="!loading">Generate</span>
|
| 75 |
+
<span x-show="loading">Generating...</span>
|
| 76 |
+
<svg x-show="!loading" xmlns="http://www.w3.org/2000/svg" class="h-4 w-4"
|
| 77 |
+
viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none"
|
| 78 |
+
stroke-linecap="round" stroke-linejoin="round">
|
| 79 |
+
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
|
| 80 |
+
<path d="M10 14l11 -11"></path>
|
| 81 |
+
<path
|
| 82 |
+
d="M21 3l-6.5 18a.55 .55 0 0 1 -1 0l-3.5 -7l-7 -3.5a.55 .55 0 0 1 0 -1l18 -6.5">
|
| 83 |
+
</path>
|
| 84 |
+
</svg>
|
| 85 |
+
</button>
|
| 86 |
+
<button type="reset"
|
| 87 |
+
class="ml-2 inline-flex items-center gap-x-2 rounded-lg bg-slate-700 px-4 py-2.5 text-center text-base font-medium text-slate-50 hover:bg-blue-600 focus:ring-4 focus:ring-blue-200 dark:focus:ring-blue-900">
|
| 88 |
+
Cancel
|
| 89 |
+
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" viewBox="0 0 24 24"
|
| 90 |
+
stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round"
|
| 91 |
+
stroke-linejoin="round">
|
| 92 |
+
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
|
| 93 |
+
<path d="M18 6l-12 12"></path>
|
| 94 |
+
<path d="M6 6l12 12"></path>
|
| 95 |
+
</svg>
|
| 96 |
+
</button>
|
| 97 |
+
</div>
|
| 98 |
+
</div>
|
| 99 |
+
</div>
|
| 100 |
+
<div
|
| 101 |
+
class="mx-auto grid w-full max-w-3xl grid-cols-2 gap-4 text-xs text-slate-600 sm:grid-cols-3 sm:gap-2 sm:text-sm md:grid-cols-4 md:text-base">
|
| 102 |
+
<button type="button"
|
| 103 |
+
@click="updateContent('Write Code in html and css for a simple web page')"
|
| 104 |
+
class="rounded-lg bg-slate-200 p-2 hover:bg-blue-600 hover:text-slate-200">
|
| 105 |
+
Code HTML
|
| 106 |
+
</button>
|
| 107 |
+
<button type="button" @click="updateContent('Write Code in python to print Hello World')"
|
| 108 |
+
class="rounded-lg bg-slate-200 p-2 hover:bg-blue-600 hover:text-slate-200">
|
| 109 |
+
Code Python
|
| 110 |
+
</button>
|
| 111 |
+
<button type="button"
|
| 112 |
+
@click="updateContent('Write Code in javascript to print Hello World')"
|
| 113 |
+
class="rounded-lg bg-slate-200 p-2 hover:bg-blue-600 hover:text-slate-200">
|
| 114 |
+
Code Js
|
| 115 |
+
</button>
|
| 116 |
+
<button type="button"
|
| 117 |
+
@click="updateContent('Write Code in HTML+CSS code and login page Using components from Bootstrap CSS framework')"
|
| 118 |
+
class="rounded-lg bg-slate-200 p-2 hover:bg-blue-600 hover:text-slate-200">
|
| 119 |
+
Code Login
|
| 120 |
+
</button>
|
| 121 |
+
</div>
|
| 122 |
+
</form>
|
| 123 |
+
|
| 124 |
+
</div>
|
| 125 |
+
|
| 126 |
+
</div>
|
| 127 |
+
|
| 128 |
</div>
|
| 129 |
+
<div class="hero rounded-3xl md:h-screen bg-stone-200 transition-[width] delay-150 ease-in-out w-full ml-2.5 md:w-6/6 md:w-4/6"
|
| 130 |
+
:class="{ 'md:w-4/6': open, 'md:w-0': !open }">
|
| 131 |
+
<div class="flex flex-col transition-[width] delay-150 ease-in-out md:h-screen w-full"
|
| 132 |
+
:class="{ 'md:w-4/6': open, 'md:w-0': !open }">
|
| 133 |
+
|
| 134 |
+
<fram id="iframe" class="border-none w-full md:min-h-screen" src="">
|
| 135 |
+
<div x-show="open" class="relative max-w-2xl mx-auto mt-11">
|
| 136 |
+
<div class="flex space-x-1 rounded-lg" role="tablist" aria-orientation="horizontal">
|
| 137 |
+
<button @click="activeTab = 'code'"
|
| 138 |
+
:class="{ 'bg-white shadow': activeTab === 'code', 'bg-transparent': activeTab !== 'code' }"
|
| 139 |
+
class="flex items-center rounded-md py-[0.4375rem] pl-2 pr-2 text-sm font-semibold lg:pr-3 text-slate-600"
|
| 140 |
+
id="headlessui-tabs-tab-14" role="tab" type="button" aria-selected="false" tabindex="-1"
|
| 141 |
+
data-headlessui-state="" aria-controls="headlessui-tabs-panel-16">
|
| 142 |
+
<svg class="h-5 w-5 flex-none "
|
| 143 |
+
:class="{ 'stroke-slate-600': activeTab !== 'code', 'stroke-sky-500': activeTab == 'code' }"
|
| 144 |
+
fill="none" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"
|
| 145 |
+
xmlns="http://www.w3.org/2000/svg">
|
| 146 |
+
<path d="m13.75 6.75 3.5 3.25-3.5 3.25M6.25 13.25 2.75 10l3.5-3.25"></path>
|
| 147 |
+
</svg><span class="sr-only lg:not-sr-only lg:ml-2"
|
| 148 |
+
:class="{ 'text-slate-400': activeTab !== 'code', 'text-slate-600': activeTab == 'code' }">Code</span>
|
| 149 |
+
</button>
|
| 150 |
+
<button @click="activeTab = 'preview'"
|
| 151 |
+
:class="{ 'bg-white shadow': activeTab === 'preview', 'bg-transparent': activeTab !== 'preview' }"
|
| 152 |
+
class="flex items-center rounded-md py-[0.4375rem] pl-2 pr-2 text-sm font-semibold lg:pr-3 text-white"
|
| 153 |
+
id="headlessui-tabs-tab-13" role="tab" type="button" aria-selected="true" tabindex="0"
|
| 154 |
+
data-headlessui-state="selected" aria-controls="headlessui-tabs-panel-15">
|
| 155 |
+
<svg class="h-5 w-5 flex-none"
|
| 156 |
+
:class="{ 'stroke-slate-600': activeTab !== 'preview', 'stroke-sky-500': activeTab == 'preview' }"
|
| 157 |
+
fill="none" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"
|
| 158 |
+
xmlns="http://www.w3.org/2000/svg">
|
| 159 |
+
<path
|
| 160 |
+
d="M17.25 10c0 1-1.75 6.25-7.25 6.25S2.75 11 2.75 10 4.5 3.75 10 3.75 17.25 9 17.25 10Z">
|
| 161 |
+
</path>
|
| 162 |
+
<circle cx="10" cy="10" r="2.25"></circle>
|
| 163 |
+
</svg><span class="sr-only lg:not-sr-only lg:ml-2"
|
| 164 |
+
:class="{ 'text-slate-400': activeTab !== 'preview', 'text-slate-600': activeTab == 'preview' }">Preview</span>
|
| 165 |
+
</button>
|
| 166 |
+
</div>
|
| 167 |
+
<div id="previewContainer" class="bg-gray-900 text-white p-4 rounded-md"
|
| 168 |
+
x-show="activeTab === 'code'" style="display: none; overflow-y: auto; max-height: 80vh;">
|
| 169 |
+
|
| 170 |
+
<div class="flex justify-between items-center mb-2">
|
| 171 |
+
<span class="text-gray-400" id="langName">Code:</span>
|
| 172 |
+
<button @click="copyGeneratedCode" data-clipboard-target="#code"
|
| 173 |
+
class="code inline-flex cursor-pointer items-center justify-center gap-1 rounded-lg bg-slate-200 p-3 text-slate-800 transition-colors hover:bg-slate-300 dark:bg-slate-700 dark:text-slate-200 dark:hover:bg-slate-800">
|
| 174 |
+
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" viewBox="0 0 24 24"
|
| 175 |
+
stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round"
|
| 176 |
+
stroke-linejoin="round">
|
| 177 |
+
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
|
| 178 |
+
<path
|
| 179 |
+
d="M9 5h-2a2 2 0 0 0 -2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2 -2v-12a2 2 0 0 0 -2 -2h-2">
|
| 180 |
+
</path>
|
| 181 |
+
<path
|
| 182 |
+
d="M9 3m0 2a2 2 0 0 1 2 -2h2a2 2 0 0 1 2 2v0a2 2 0 0 1 -2 2h-2a2 2 0 0 1 -2 -2z">
|
| 183 |
+
</path>
|
| 184 |
+
</svg>
|
| 185 |
+
<span class="text-sm font-medium">Copy</span>
|
| 186 |
+
<span class="sr-only">Copy</span>
|
| 187 |
+
</button>
|
| 188 |
+
</div>
|
| 189 |
+
|
| 190 |
+
<div class="overflow-x-auto">
|
| 191 |
+
<pre id="generated-code" class="text-gray-300">
|
| 192 |
+
<code></code>
|
| 193 |
+
</pre>
|
| 194 |
+
</div>
|
| 195 |
+
</div>
|
| 196 |
+
<div class="bg-gray-900 text-white p-4 rounded-md"
|
| 197 |
+
x-show="activeTab === 'preview' && langName === 'html'">
|
| 198 |
+
<div class="flex justify-between items-center mb-2">
|
| 199 |
+
<span class="text-gray-400" id="langName">Preview:</span>
|
| 200 |
+
<button class="code bg-gray-800 hover:bg-gray-700 text-gray-300 px-3 py-1 rounded-md"
|
| 201 |
+
@click="tryIt">
|
| 202 |
+
Try it
|
| 203 |
+
</button>
|
| 204 |
+
</div>
|
| 205 |
+
<div class="overflow-x-auto">
|
| 206 |
+
<div id="PreviewCode"></div>
|
| 207 |
+
</div>
|
| 208 |
+
</div>
|
| 209 |
+
</div>
|
| 210 |
+
</fram>
|
| 211 |
+
<div x-show="loading" class="flex w-full -mt-20 items-end justify-center pointer-events-none"
|
| 212 |
+
:style="{ 'display': open ? 'block' : 'none' }">
|
| 213 |
+
<div class="flex flex-row py-3 px-8 text-center bg-stone-200 text-stone-600 rounded-md shadow-md">
|
| 214 |
+
<div class="animate-bounce duration-150 mr-1">🤖</div>
|
| 215 |
+
<div>Generating your app..</div>
|
| 216 |
+
</div>
|
| 217 |
+
</div>
|
| 218 |
+
</div>
|
| 219 |
+
</div>
|
| 220 |
+
</div>
|
| 221 |
+
<script>
|
| 222 |
+
function app() {
|
| 223 |
+
return {
|
| 224 |
+
open: false,
|
| 225 |
+
loading: false,
|
| 226 |
+
selectedPrompt: null,
|
| 227 |
+
activeTab: 'code',
|
| 228 |
+
langName: 'Code:',
|
| 229 |
+
isFirstToggle: true,
|
| 230 |
+
openModal: false,
|
| 231 |
+
selectedModel: 'codellama/CodeLlama-34b-Instruct-hf',
|
| 232 |
+
PageModel: 'https://huggingface.co/codellama/CodeLlama-34b-Instruct-hf',
|
| 233 |
+
WebSiteModel: 'https://about.fb.com/news/2023/08/code-llama-ai-for-coding',
|
| 234 |
+
|
| 235 |
+
selectModel(model, website) {
|
| 236 |
+
this.selectedModel = model;
|
| 237 |
+
this.PageModel = `https://huggingface.co/${model}`;
|
| 238 |
+
this.WebSiteModel = website;
|
| 239 |
+
this.openModal = false;
|
| 240 |
+
document.getElementById('ModelName').textContent = `${this.selectedModel}`;
|
| 241 |
+
|
| 242 |
+
},
|
| 243 |
+
init() {
|
| 244 |
+
|
| 245 |
+
},
|
| 246 |
+
async generateCode() {
|
| 247 |
+
if (this.isFirstToggle) {
|
| 248 |
+
this.open = true;
|
| 249 |
+
this.isFirstToggle = false;
|
| 250 |
+
}
|
| 251 |
+
this.loading = !this.loading;
|
| 252 |
+
const userPrompt = document.getElementById('prompt-input').value;
|
| 253 |
+
|
| 254 |
+
const htmlFormatPrompt = `Generate HTML code with proper formatting: ${userPrompt}`;
|
| 255 |
+
console.log('Prompt:', htmlFormatPrompt);
|
| 256 |
+
try {
|
| 257 |
+
const response = await axios.post(`https://api-inference.huggingface.co/models/${this.selectedModel}`, {
|
| 258 |
+
inputs: htmlFormatPrompt,
|
| 259 |
+
}, {
|
| 260 |
+
headers: {
|
| 261 |
+
'Authorization': 'Bearer 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',
|
| 262 |
+
},
|
| 263 |
+
});
|
| 264 |
+
const generatedTextParts = response.data[0].generated_text.split('```');
|
| 265 |
+
const extractedCode = generatedTextParts[1].trim(); // Trim to remove leading/trailing spaces
|
| 266 |
+
|
| 267 |
+
if (extractedCode.toLowerCase().includes('<!doctype html>')) {
|
| 268 |
+
this.langName = 'html';
|
| 269 |
+
} else {
|
| 270 |
+
const programmingLanguages = ['html', 'javascript', 'python', 'php', 'c++'];
|
| 271 |
+
programmingLanguages.forEach(lang => {
|
| 272 |
+
if (extractedCode.toLowerCase().includes(lang)) {
|
| 273 |
+
this.langName = lang;
|
| 274 |
+
}
|
| 275 |
+
});
|
| 276 |
+
}
|
| 277 |
+
|
| 278 |
+
const modifiedCode = extractedCode.replace(new RegExp(this.langName, 'i'), '').trim();
|
| 279 |
+
document.getElementById('generated-code').textContent = modifiedCode;
|
| 280 |
+
document.getElementById('langName').textContent = `${this.langName}`;
|
| 281 |
+
document.getElementById('PreviewCode').innerHTML = modifiedCode;
|
| 282 |
+
|
| 283 |
+
} catch (error) {
|
| 284 |
+
console.error('Error generating code:', error);
|
| 285 |
+
} finally {
|
| 286 |
+
this.loading = !this.loading;
|
| 287 |
+
}
|
| 288 |
+
},
|
| 289 |
+
updateContent(prompt) {
|
| 290 |
+
document.getElementById('prompt-input').value = prompt;
|
| 291 |
+
},
|
| 292 |
+
copyGeneratedCode() {
|
| 293 |
+
const clipboard = new ClipboardJS('.code', {
|
| 294 |
+
target: function (trigger) {
|
| 295 |
+
return document.getElementById('generated-code');
|
| 296 |
+
}
|
| 297 |
+
});
|
| 298 |
+
|
| 299 |
+
clipboard.on('success', function (e) {
|
| 300 |
+
console.log('Code copied to clipboard:', e.text);
|
| 301 |
+
clipboard.destroy();
|
| 302 |
+
|
| 303 |
+
});
|
| 304 |
+
|
| 305 |
+
clipboard.on('error', function (e) {
|
| 306 |
+
console.error('Error copying code:', e.action);
|
| 307 |
+
|
| 308 |
+
});
|
| 309 |
+
},
|
| 310 |
+
updatePreviewContent(htmlContent) {
|
| 311 |
+
const previewContainer = document.getElementById('previewContainer');
|
| 312 |
+
|
| 313 |
+
previewContainer.innerHTML = htmlContent;
|
| 314 |
+
},
|
| 315 |
+
tryIt() {
|
| 316 |
+
const modifiedCode = document.getElementById('PreviewCode').innerHTML;
|
| 317 |
+
|
| 318 |
+
const previewWindow = window.open('', '_blank');
|
| 319 |
+
previewWindow.document.write(`${modifiedCode}`);
|
| 320 |
+
}
|
| 321 |
+
};
|
| 322 |
+
}
|
| 323 |
+
</script>
|
| 324 |
+
</body>
|
| 325 |
+
|
| 326 |
+
</html>
|
style.css
DELETED
|
@@ -1,28 +0,0 @@
|
|
| 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 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|