man08man commited on
Commit
0238a29
·
verified ·
1 Parent(s): 07dc90b

Upload index.html

Browse files
Files changed (1) hide show
  1. index.html +48 -0
index.html ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script>
2
+ const HF_TOKEN = "YOUR_HUGGING_FACE_TOKEN"; // Replace with your token
3
+
4
+ async function generateImage() {
5
+ const prompt = document.getElementById("prompt").value;
6
+ const imageContainer = document.getElementById("image");
7
+
8
+ if (!prompt) {
9
+ imageContainer.innerHTML = "Please enter a prompt.";
10
+ return;
11
+ }
12
+
13
+ imageContainer.innerHTML = "Generating...";
14
+
15
+ try {
16
+ // Generate a RANDOM SEED (0 to 1,000,000)
17
+ const randomSeed = Math.floor(Math.random() * 1000000);
18
+
19
+ // Add parameters for randomness
20
+ const response = await fetch(
21
+ "https://api-inference.huggingface.co/models/runwayml/stable-diffusion-v1-5",
22
+ {
23
+ method: "POST",
24
+ headers: {
25
+ "Authorization": `Bearer ${HF_TOKEN}`,
26
+ "Content-Type": "application/json",
27
+ },
28
+ body: JSON.stringify({
29
+ inputs: prompt,
30
+ parameters: {
31
+ seed: randomSeed, // Random seed for variation
32
+ guidance_scale: 7.5, // Controls creativity (7-15)
33
+ num_inference_steps: 50 // More steps = more details (20-100)
34
+ }
35
+ }),
36
+ }
37
+ );
38
+
39
+ if (!response.ok) throw new Error("API error: " + response.status);
40
+
41
+ const imageBlob = await response.blob();
42
+ const imageUrl = URL.createObjectURL(imageBlob);
43
+ imageContainer.innerHTML = `<img src="${imageUrl}" style="max-width:100%;">`;
44
+ } catch (error) {
45
+ imageContainer.innerHTML = "Error: " + error.message;
46
+ }
47
+ }
48
+ </script>