File size: 7,332 Bytes
3948dee
d21b859
3948dee
fd71c00
3948dee
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fd71c00
3948dee
 
 
 
 
fd71c00
3948dee
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fd71c00
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3948dee
 
 
 
 
 
 
 
 
 
 
8398b03
3948dee
187d912
3948dee
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d21b859
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
<!DOCTYPE html>
<html>
<head>
  <title>WebGenUI - Web Page UI Generator</title>
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css">
  <style>
/* Style the form container */
.form-container {
  max-width: 600px;
  margin: 0 auto;
  padding: 20px;
  border: 1px solid #ccc;
  border-radius: 5px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

/* Style the form heading */
h1 {
  font-size: 24px;
  font-weight: bold;
  margin-bottom: 20px;
}

/* Style the form icon */
.form-icon {
  margin-right: 10px;
}

/* Style the group headings */
h2 {
  font-size: 20px;
  font-weight: bold;
  margin-bottom: 10px;
  padding: 10px;
  border: 1px solid #ccc;
  border-radius: 5px;
}

/* Style the group icon */
.group-icon {
  margin-right: 5px;
}

/* Style the form fields */
.form-field {
  margin-bottom: 10px;
}

/* Style the form field labels */
.form-field label {
  font-weight: bold;
}

/* Style the form field inputs */
.form-field input,
.form-field textarea,
.form-field select {
  width: 100%;
}

/* Style the form field checkboxes and radios */
.form-field input[type="checkbox"],
.form-field input[type="radio"] {
  margin-right: 5px;
}

/* Style the form field checkbox and radio labels */
.form-field label[for] {
  display: inline;
  font-weight: normal;
}

/* Style the form field error messages */
.form-field .error-message {
  color: red;
  font-size: 12px;
  margin-top: 5px;
}

/* Style the form submit and cancel buttons */
.form-buttons {
  margin-top: 20px;
}

.form-buttons button {
  padding: 10px 20px;
  border: none;
  border-radius: 5px;
  cursor: pointer;
}

.form-buttons button[type="submit"] {
  background-color: #4CAF50;
  color: white;
  margin-right: 10px;
}

.form-buttons button[type="reset"] {
  background-color: #f44336;
  color: white;
}

/* Use Bootstrap classes to style the form and group headings */
.form-container {
  border: none;
  box-shadow: none;
  padding: 2rem;
  background-color: #f8f9fa;
  border-radius: 0.25rem;
}

h1 {
  font-size: 2.5rem;
  margin-bottom: 2rem;
}

h2 {
  font-size: 1.5rem;
  margin-bottom: 1rem;
  padding: 0.5rem 1rem;
  background-color: #e9ecef;
  border-radius: 0.25rem;
  border: none;
}

.form-field {
  margin-bottom: 1rem;
}

.form-field label {
  font-weight: bold;
  margin-bottom: 0.25rem;
}

.form-field input,
.form-field textarea,
.form-field select {
  border-radius: 0.25rem;
}

.form-buttons button {
  padding: 0.5rem 1rem;
  border-radius: 0.25rem;
}

.form-buttons button[type="submit"] {
  background-color: #007bff;
  border-color: #007bff;
}

.form-buttons button[type="reset"] {
  background-color: #dc3545;
  border-color: #dc3545;
}


  </style>
</head>
<body>
    <div class="container" style="margin-top: 50px;">
        <form id="messageForm">
            <div class="input-group mb-3">
                <input type="text" class="form-control" id="messageInput" placeholder="Type your website details here...">
                 <!-- <textarea class="form-control" id="messageInput" placeholder="Type your message here..." rows="7"></textarea> -->
                <div class="input-group-append">
                    <button class="btn btn-outline-secondary" type="submit" id="sendButton">
                        <i id="buttonIcon" class="fas fa-paper-plane"></i>
                    </button>
                  <button id="downloadButton"><i class="fas fa-download"></i> Download HTML</button>
                </div>
            </div>
        </form>
    </div>

      <div class="container-fluid" id="htmlDiv">
        <div class=" embed-responsive-16by9">
    <iframe id="myIframe" class="embed-responsive-item" style="width: 100%;border: none;"></iframe>
  </div>
  </div>

      <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
      <script>
  //        document.getElementById('myIframe').onload = function() {
  //         document.getElementById('myIframe').style.height = document.getElementById('myIframe').contentWindow.document.body.scrollHeight + 'px';
  //         //document.getElementById('htmlDiv').style.height = document.getElementById('myIframe').contentWindow.document.body.scrollHeight  + 'px';
          
  // }

  var iframe = document.getElementById('myIframe');
  iframe.onload = function() {
    iframe.contentWindow.document.body.style.margin = '0';
    iframe.contentWindow.document.body.style.padding = '0';
    iframe.style.height = document.getElementById('myIframe').contentWindow.document.body.scrollHeight + 'px';
   
  }

document.getElementById('downloadButton').addEventListener('click', function() {
    var iframeDoc = document.getElementById('myIframe').contentWindow.document;
    if (iframeDoc.body.innerHTML.trim() !== '') {
        var html = iframeDoc.documentElement.outerHTML;
        var blob = new Blob([html], { type: 'text/html' });
        var url = URL.createObjectURL(blob);
        var a = document.createElement('a');
        a.href = url;
        a.download = 'output.html';
        document.body.appendChild(a);
        a.click();
        document.body.removeChild(a);
        URL.revokeObjectURL(url);
    } else {
        alert('No content to download.');
    }
});

          $(document).ready(function() {
              $('#messageForm').on('submit', function(e) {
                  e.preventDefault();
                  var message = $('#messageInput').val();
                  var buttonIcon = $('#buttonIcon');
                  //$("#htmlPreview").html('');
                  // Change icon to loading spinner
                  document.getElementById('myIframe').srcdoc = '';
                  buttonIcon.removeClass('fa-paper-plane').addClass('fa-spinner fa-spin');
                  
                  $.ajax({
                      url: 'https://nakheeltech.com:8030/api/v1/prediction/9b2e5787-04ce-404c-981f-a69bbfce6035',
                      type: 'POST',
                      data: JSON.stringify({"question":  message }),
                      contentType: 'application/json',
                      success: function(data) {
                          // Change icon back to paper plane
                          $('#messageInput').val('');
                          var text=data.text
                          var startIndex = text.indexOf("<");
                            var endIndex = text.lastIndexOf(">") + 1;
                            var htmlString = text.substring(startIndex, endIndex);
                            document.getElementById('myIframe').srcdoc = htmlString;
                            //$("#htmlPreview").html(htmlString);
                          buttonIcon.removeClass('fa-spinner fa-spin').addClass('fa-paper-plane');
                          // Handle success here
                      },
                      error: function(jqXHR, textStatus, errorThrown) {
                          // Change icon back to paper plane
                          buttonIcon.removeClass('fa-spinner fa-spin').addClass('fa-paper-plane');
                          // Handle error here
                      }
                  });
              });
          });
      </script>

<!-- <div class="container" id="htmlPreview">

</div> -->
</body>
</html>