-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
92 lines (72 loc) · 3.06 KB
/
index.html
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
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" href="/txttoimglogo.jpeg" />
<link rel="stylesheet" href="style.css"/>
<script src="https://kit.fontawesome.com/789ac54095.js" crossorigin="anonymous"></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Image generator</title>
</head>
<body>
<canvas class="orb-canvas"></canvas>
<section class="overlay">
<div class="overlay__inner">
<div class="overlay__title">
<h1> </h1>
<input type="text" id="promptInput" placeholder="Enter your prompt here">
<button onclick="sendPrompt()">Generate</button>
</div>
<div class="overlay__description">
<div id="resultContainer" >
<!-- The generated image will be displayed here -->
</div>
<div id="imageDownload">
</div>
</div>
</div>
</section>
<script>
// Function to send the prompt and get the generated image
async function sendPrompt() {
const promptInput = document.getElementById('promptInput').value;
const headers = {
"Authorization": "Bearer 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",
};
const requestOptions = {
method: "POST",
headers: headers,
body: JSON.stringify({ "inputs": promptInput })
};
try {
const response = await fetch("https://api-inference.huggingface.co/models/prompthero/openjourney", requestOptions);
const imageBlob = await response.blob();
const imageURL = URL.createObjectURL(imageBlob);
displayResult(imageURL);
} catch (error) {
console.error('Error:', error);
}
}
// Function to display the generated image
function displayResult(imageURL) {
const resultContainer = document.getElementById('resultContainer');
resultContainer.innerHTML = `<img id="downloadImg" src="${imageURL}" alt="Generated Image" class="image">`;
const imageDownload = document.getElementById('imageDownload');
imageDownload.innerHTML = `<button id="downloadButton"><i class="fa-solid fa-download"></i></button>`;
const downloadButton = document.getElementById('downloadButton');
downloadButton.addEventListener('click', downloadImage);
}
function downloadImage() {
const imgElement = document.getElementById('downloadImg');
const imgURL = imgElement.src;
const fileName = 'downloaded_image.jpg';
const link = document.createElement('a');
link.innerText = "Working...";
link.href = imgURL;
link.download = fileName;
link.click();
}
</script>
<script src="main.js" type="module"></script>
</body>
</html>