Update src/streamlit_app.py
Browse files- src/streamlit_app.py +33 -39
src/streamlit_app.py
CHANGED
@@ -1,40 +1,34 @@
|
|
1 |
-
import altair as alt
|
2 |
-
import numpy as np
|
3 |
-
import pandas as pd
|
4 |
import streamlit as st
|
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 |
-
color=alt.Color("idx", legend=None, scale=alt.Scale()),
|
39 |
-
size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
|
40 |
-
))
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
from huggingface_hub import InferenceClient
|
3 |
+
from PIL import Image
|
4 |
+
import io
|
5 |
+
|
6 |
+
# Streamlit UI setup
|
7 |
+
st.set_page_config(page_title="Text-to-Image Generator", layout="centered")
|
8 |
+
st.title("🖼️ Text to Image Generator")
|
9 |
+
st.markdown("Enter a prompt and generate an image using the Flux model from Hugging Face.")
|
10 |
+
|
11 |
+
# Input for the prompt
|
12 |
+
prompt = st.text_input("Enter your prompt", "Astronaut riding a horse")
|
13 |
+
|
14 |
+
# Generate button
|
15 |
+
if st.button("Generate Image"):
|
16 |
+
with st.spinner("Generating... please wait"):
|
17 |
+
try:
|
18 |
+
# Initialize the Inference Client
|
19 |
+
client = InferenceClient(
|
20 |
+
provider="fal-ai",
|
21 |
+
api_key=st.secrets["TOGETHER_API_KEY"], # Store your key in .streamlit/secrets.toml
|
22 |
+
)
|
23 |
+
|
24 |
+
# Generate image
|
25 |
+
image = client.text_to_image(
|
26 |
+
prompt,
|
27 |
+
model="black-forest-labs/FLUX.1-dev",
|
28 |
+
)
|
29 |
+
|
30 |
+
# Show image
|
31 |
+
st.image(image, caption=f"Generated Image for: {prompt}", use_column_width=True)
|
32 |
+
|
33 |
+
except Exception as e:
|
34 |
+
st.error(f"Error: {str(e)}")
|
|
|
|
|
|