SJCET2 commited on
Commit
a9ef680
Β·
verified Β·
1 Parent(s): 6c33138

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+ import io
4
+ from PIL import Image
5
+ import os
6
+
7
+ # API Configuration
8
+ API_URL = "https://api-inference.huggingface.co/models/black-forest-labs/FLUX.1-dev"
9
+ headers = {"Authorization": f"Bearer {os.getenv('HUGGINGFACE_API_KEY')}"}
10
+
11
+ # Function to query the Hugging Face API
12
+ def query(payload):
13
+ response = requests.post(API_URL, headers=headers, json=payload)
14
+ return response.content
15
+
16
+ # Streamlit UI
17
+ st.title("AI Image Generator πŸŽ¨πŸš€")
18
+ st.write("Enter a prompt below and generate an AI-generated image using Hugging Face!")
19
+
20
+ # User Input
21
+ prompt = st.text_input("Enter your prompt:", "Astronaut riding a horse")
22
+
23
+ if st.button("Generate Image"):
24
+ if prompt:
25
+ st.write("Generating image... Please wait ⏳")
26
+ image_bytes = query({"inputs": prompt})
27
+
28
+ # Display Image
29
+ image = Image.open(io.BytesIO(image_bytes))
30
+ st.image(image, caption="Generated Image", use_column_width=True)
31
+ else:
32
+ st.warning("Please enter a prompt before generating an image.")
33
+
34
+ # Footer
35
+ st.write("---")
36
+ st.write("Powered by [Hugging Face](https://huggingface.co/) πŸš€")