File size: 1,133 Bytes
cc23a8c
6b270d6
 
 
cc23a8c
6b270d6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

from huggingface_hub import InferenceClient
from PIL import Image
import io
import streamlit as st
# Streamlit UI setup
st.set_page_config(page_title="Text-to-Image Generator", layout="centered")
st.title("🖼️ Text to Image Generator")
st.markdown("Enter a prompt and generate an image using the Flux model from Hugging Face.")

# Input for the prompt
prompt = st.text_input("Enter your prompt", "Astronaut riding a horse")

# Generate button
if st.button("Generate Image"):
    with st.spinner("Generating... please wait"):
        try:
            # Initialize the Inference Client
            client = InferenceClient(
                provider="fal-ai",
                api_key=st.secrets["TOGETHER_API_KEY"],  # Store your key in .streamlit/secrets.toml
            )

            # Generate image
            image = client.text_to_image(
                prompt,
                model="black-forest-labs/FLUX.1-dev",
            )

            # Show image
            st.image(image, caption=f"Generated Image for: {prompt}", use_column_width=True)

        except Exception as e:
            st.error(f"Error: {str(e)}")