man08man commited on
Commit
168e5ba
·
verified ·
1 Parent(s): 0238a29

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +17 -48
index.html CHANGED
@@ -1,48 +1,17 @@
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>
 
1
+ import streamlit as st
2
+ from diffusers import StableDiffusionPipeline
3
+ import torch
4
+
5
+ # Load the model
6
+ model_id = "runwayml/stable-diffusion-v1-5"
7
+ pipe = StableDiffusionPipeline.from_pretrained(model_id)
8
+ pipe = pipe.to("cuda") # Runs on Hugging Face's GPU servers
9
+
10
+ # Streamlit UI
11
+ st.title("Free AI Image Generator")
12
+ prompt = st.text_input("Describe your image...")
13
+
14
+ if prompt:
15
+ with st.spinner("Generating..."):
16
+ image = pipe(prompt).images[0]
17
+ st.image(image, caption=prompt, use_column_width=True)