Advait3009 commited on
Commit
b6290e5
·
verified ·
1 Parent(s): 7d3df40

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +28 -23
index.html CHANGED
@@ -658,15 +658,6 @@
658
  <input type="range" id="genSteps" min="10" max="50" step="1" value="20">
659
  </div>
660
  </div>
661
-
662
- <div class="form-group">
663
- <label for="imageSize">Image Size</label>
664
- <select id="imageSize">
665
- <option value="512">512×512</option>
666
- <option value="768">768×768</option>
667
- <option value="1024">1024×1024</option>
668
- </select>
669
- </div>
670
  </div>
671
 
672
  <button class="btn btn-primary" id="generateImageBtn">
@@ -772,7 +763,7 @@
772
 
773
  <script>
774
  // API configuration
775
- const API_URL = "https://multimodalart-cosxl.hf.space/api/predict";
776
 
777
  // DOM Elements
778
  const tabs = document.querySelectorAll('.tab');
@@ -949,14 +940,14 @@
949
 
950
  // Create payload
951
  const payload = {
 
952
  data: [
953
  "data:image/png;base64," + base64Data,
954
  prompt,
955
  negativePrompt,
956
  guidance,
957
  stepsValue
958
- ],
959
- fn_index: 3 // The edit endpoint index
960
  };
961
 
962
  // Call API
@@ -996,13 +987,12 @@
996
  }
997
  }
998
 
999
- // API call for text-to-image generation
1000
  async function generateImage() {
1001
  const prompt = document.getElementById('generatePrompt').value;
1002
  const negativePrompt = document.getElementById('generateNegPrompt').value;
1003
  const guidance = parseFloat(document.getElementById('genGuidanceScale').value);
1004
  const stepsValue = parseInt(document.getElementById('genSteps').value);
1005
- const imageSize = document.getElementById('imageSize').value;
1006
 
1007
  if (!prompt) {
1008
  showNotification(errorNotification, 'Please enter a prompt');
@@ -1013,17 +1003,15 @@
1013
  generateLoading.classList.add('active');
1014
 
1015
  try {
1016
- // Create payload
1017
  const payload = {
 
1018
  data: [
1019
  prompt,
1020
- negativePrompt,
1021
  guidance,
1022
- stepsValue,
1023
- parseInt(imageSize),
1024
- parseInt(imageSize)
1025
- ],
1026
- fn_index: 0 // The text-to-image endpoint index
1027
  };
1028
 
1029
  // Call API
@@ -1042,11 +1030,14 @@
1042
  const data = await response.json();
1043
 
1044
  if (data && data.data && data.data[0]) {
 
 
 
1045
  // Set the generated image
1046
- generatedImage.src = data.data[0];
1047
  generatedImage.style.display = 'block';
1048
  document.querySelector('#generateOutputPreview .placeholder').style.display = 'none';
1049
- generatedImageData = data.data[0];
1050
 
1051
  // Enable download button
1052
  downloadGeneratedBtn.disabled = false;
@@ -1078,6 +1069,7 @@
1078
  downloadGeneratedBtn.addEventListener('click', () => {
1079
  if (!generatedImageData) return;
1080
 
 
1081
  const link = document.createElement('a');
1082
  link.href = generatedImageData;
1083
  link.download = 'cosxl-generated-image.jpg';
@@ -1107,6 +1099,19 @@
1107
  document.getElementById('generatePrompt').value = 'A beautiful landscape with mountains and a lake';
1108
  document.getElementById('generateNegPrompt').value = 'blurry, low quality';
1109
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1110
  // Show first tab
1111
  document.getElementById('edit-tab').classList.remove('hidden');
1112
 
 
658
  <input type="range" id="genSteps" min="10" max="50" step="1" value="20">
659
  </div>
660
  </div>
 
 
 
 
 
 
 
 
 
661
  </div>
662
 
663
  <button class="btn btn-primary" id="generateImageBtn">
 
763
 
764
  <script>
765
  // API configuration
766
+ const API_URL = "https://multimodalart-cosxl.hf.space/api/predict/";
767
 
768
  // DOM Elements
769
  const tabs = document.querySelectorAll('.tab');
 
940
 
941
  // Create payload
942
  const payload = {
943
+ fn_index: 3,
944
  data: [
945
  "data:image/png;base64," + base64Data,
946
  prompt,
947
  negativePrompt,
948
  guidance,
949
  stepsValue
950
+ ]
 
951
  };
952
 
953
  // Call API
 
987
  }
988
  }
989
 
990
+ // API call for text-to-image generation (using provided snippet)
991
  async function generateImage() {
992
  const prompt = document.getElementById('generatePrompt').value;
993
  const negativePrompt = document.getElementById('generateNegPrompt').value;
994
  const guidance = parseFloat(document.getElementById('genGuidanceScale').value);
995
  const stepsValue = parseInt(document.getElementById('genSteps').value);
 
996
 
997
  if (!prompt) {
998
  showNotification(errorNotification, 'Please enter a prompt');
 
1003
  generateLoading.classList.add('active');
1004
 
1005
  try {
1006
+ // Create payload using provided snippet structure
1007
  const payload = {
1008
+ fn_index: 4,
1009
  data: [
1010
  prompt,
1011
+ negativePrompt || "blurry, bad anatomy", // Default if empty
1012
  guidance,
1013
+ stepsValue
1014
+ ]
 
 
 
1015
  };
1016
 
1017
  // Call API
 
1030
  const data = await response.json();
1031
 
1032
  if (data && data.data && data.data[0]) {
1033
+ // Get image URL from response
1034
+ const imageUrl = data.data[0].url;
1035
+
1036
  // Set the generated image
1037
+ generatedImage.src = imageUrl;
1038
  generatedImage.style.display = 'block';
1039
  document.querySelector('#generateOutputPreview .placeholder').style.display = 'none';
1040
+ generatedImageData = imageUrl;
1041
 
1042
  // Enable download button
1043
  downloadGeneratedBtn.disabled = false;
 
1069
  downloadGeneratedBtn.addEventListener('click', () => {
1070
  if (!generatedImageData) return;
1071
 
1072
+ // Create temporary download link for generated image
1073
  const link = document.createElement('a');
1074
  link.href = generatedImageData;
1075
  link.download = 'cosxl-generated-image.jpg';
 
1099
  document.getElementById('generatePrompt').value = 'A beautiful landscape with mountains and a lake';
1100
  document.getElementById('generateNegPrompt').value = 'blurry, low quality';
1101
 
1102
+ // Initialize text-to-image sliders
1103
+ document.getElementById('genGuidanceValue').textContent = document.getElementById('genGuidanceScale').value;
1104
+ document.getElementById('genStepsValue').textContent = document.getElementById('genSteps').value;
1105
+
1106
+ // Event listeners for text-to-image sliders
1107
+ document.getElementById('genGuidanceScale').addEventListener('input', function() {
1108
+ document.getElementById('genGuidanceValue').textContent = this.value;
1109
+ });
1110
+
1111
+ document.getElementById('genSteps').addEventListener('input', function() {
1112
+ document.getElementById('genStepsValue').textContent = this.value;
1113
+ });
1114
+
1115
  // Show first tab
1116
  document.getElementById('edit-tab').classList.remove('hidden');
1117