Update app.py
Browse files
app.py
CHANGED
@@ -9,19 +9,19 @@ API_URL = "https://api-inference.huggingface.co/models/black-forest-labs/FLUX.1-
|
|
9 |
headers = {"Authorization": f"Bearer {os.getenv('HF')}"}
|
10 |
|
11 |
# Function to query the Hugging Face API
|
12 |
-
@st.cache_data(ttl=
|
13 |
-
def
|
14 |
-
response = requests.post(API_URL, headers=headers, json=
|
15 |
return response.content
|
16 |
|
17 |
# Check for 'text' parameter in URL
|
18 |
-
query_params = st.
|
19 |
-
prompt_from_url = query_params.get('text'
|
20 |
|
21 |
if prompt_from_url:
|
22 |
# If 'text' parameter is present, generate and display the image only
|
23 |
-
prompt = prompt_from_url
|
24 |
-
image_bytes =
|
25 |
image = Image.open(io.BytesIO(image_bytes))
|
26 |
st.image(image, caption="Generated Image", use_container_width=True)
|
27 |
|
@@ -46,7 +46,7 @@ else:
|
|
46 |
if st.button("Generate Image"):
|
47 |
if prompt:
|
48 |
st.write("Generating image... Please wait ⏳")
|
49 |
-
image_bytes =
|
50 |
|
51 |
# Display Image
|
52 |
image = Image.open(io.BytesIO(image_bytes))
|
|
|
9 |
headers = {"Authorization": f"Bearer {os.getenv('HF')}"}
|
10 |
|
11 |
# Function to query the Hugging Face API
|
12 |
+
@st.cache_data(ttl=60)
|
13 |
+
def query(payload):
|
14 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
15 |
return response.content
|
16 |
|
17 |
# Check for 'text' parameter in URL
|
18 |
+
query_params = st.query_params
|
19 |
+
prompt_from_url = query_params.get('text')
|
20 |
|
21 |
if prompt_from_url:
|
22 |
# If 'text' parameter is present, generate and display the image only
|
23 |
+
prompt = prompt_from_url
|
24 |
+
image_bytes = query({"inputs": prompt})
|
25 |
image = Image.open(io.BytesIO(image_bytes))
|
26 |
st.image(image, caption="Generated Image", use_container_width=True)
|
27 |
|
|
|
46 |
if st.button("Generate Image"):
|
47 |
if prompt:
|
48 |
st.write("Generating image... Please wait ⏳")
|
49 |
+
image_bytes = query({"inputs": prompt})
|
50 |
|
51 |
# Display Image
|
52 |
image = Image.open(io.BytesIO(image_bytes))
|