Update app.py
Browse files
app.py
CHANGED
|
@@ -1,30 +1,26 @@
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
from PIL import Image
|
| 3 |
-
from
|
| 4 |
-
import torch
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
processor = AutoProcessor.from_pretrained("kandinsky-community/kandinsky-2-2-decoder")
|
| 9 |
-
model = KandinskyDecoderPipeline.from_pretrained(
|
| 10 |
-
"kandinsky-community/kandinsky-2-2-decoder",
|
| 11 |
-
torch_dtype=torch.float32,
|
| 12 |
-
)
|
| 13 |
-
model.to("cpu")
|
| 14 |
-
return processor, model
|
| 15 |
|
| 16 |
-
st.
|
| 17 |
-
st.title("🎨 Kandinsky Thumbnail Generator")
|
| 18 |
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
from PIL import Image
|
| 4 |
+
from io import BytesIO
|
|
|
|
| 5 |
|
| 6 |
+
st.set_page_config(page_title="DALLE Mini Thumbnail Generator")
|
| 7 |
+
st.title("🖼️ Thumbnail Generator using DALL·E Mini")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
prompt = st.text_input("Enter your thumbnail prompt:", "Minecraft NOOB vs PRO Hardcore battle")
|
|
|
|
| 10 |
|
| 11 |
+
if st.button("Generate"):
|
| 12 |
+
with st.spinner("Generating Image..."):
|
| 13 |
+
api_url = "https://api-inference.huggingface.co/models/dalle-mini/dalle-mini/mega-1-fp16:latest"
|
| 14 |
+
headers = {"Authorization": "Bearer YOUR_HF_API_TOKEN"} # replace with real token
|
| 15 |
|
| 16 |
+
response = requests.post(api_url, headers=headers, json={"inputs": prompt})
|
| 17 |
+
if response.status_code == 200:
|
| 18 |
+
output = response.json()
|
| 19 |
+
image_url = output["generated_images"][0]
|
| 20 |
+
image_data = requests.get(image_url).content
|
| 21 |
+
image = Image.open(BytesIO(image_data))
|
| 22 |
|
| 23 |
+
st.image(image, caption="Generated Thumbnail")
|
| 24 |
+
st.success("Done!")
|
| 25 |
+
else:
|
| 26 |
+
st.error("❌ Failed to generate image. Try again later.")
|