AjithBharadwaj commited on
Commit
f659518
·
verified ·
1 Parent(s): bc13c4e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from PIL import Image
3
+ import io
4
+ import requests
5
+ import os
6
+ HF_TOKEN = os.environ["HF_TOKEN"]
7
+
8
+ def query(payload):
9
+ response = requests.post(API_URL, headers=headers, json=payload)
10
+ return response.content
11
+
12
+
13
+ def main():
14
+ st.title(":male-astronaut: Image Generator App :male-astronaut:")
15
+
16
+ # Text input box for the user
17
+ text_input = st.text_input("Enter your Imagination :")
18
+
19
+ # Button to trigger image generation
20
+ if st.button("Generate Image"):
21
+ # Call image_generator function
22
+
23
+
24
+ API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl-base-1.0"
25
+ headers = {"Authorization": f"Bearer {HF_TOKEN}"}
26
+ image_bytes = query({
27
+ "inputs": text_input,
28
+ })
29
+ image = Image.open(io.BytesIO(image_bytes))
30
+
31
+ # Display the generated image
32
+ st.image(image, caption='Generated Image', use_column_width=True)
33
+
34
+ if __name__ == "__main__":
35
+ main()