File size: 1,073 Bytes
51a2af7
d18ce2f
51a2af7
d18ce2f
51a2af7
d18ce2f
 
51a2af7
d18ce2f
51a2af7
d18ce2f
 
 
 
51a2af7
d18ce2f
 
 
 
 
 
51a2af7
d18ce2f
 
 
 
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
import streamlit as st
import requests
from PIL import Image
from io import BytesIO

st.set_page_config(page_title="DALLE Mini Thumbnail Generator")
st.title("🖼️ Thumbnail Generator using DALL·E Mini")

prompt = st.text_input("Enter your thumbnail prompt:", "Minecraft NOOB vs PRO Hardcore battle")

if st.button("Generate"):
    with st.spinner("Generating Image..."):
        api_url = "https://api-inference.huggingface.co/models/dalle-mini/dalle-mini/mega-1-fp16:latest"
        headers = {"Authorization": "Bearer YOUR_HF_API_TOKEN"}  # replace with real token

        response = requests.post(api_url, headers=headers, json={"inputs": prompt})
        if response.status_code == 200:
            output = response.json()
            image_url = output["generated_images"][0]
            image_data = requests.get(image_url).content
            image = Image.open(BytesIO(image_data))

            st.image(image, caption="Generated Thumbnail")
            st.success("Done!")
        else:
            st.error("❌ Failed to generate image. Try again later.")