Kvikontent commited on
Commit
8a6fc44
Β·
verified Β·
1 Parent(s): 1679881

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -0
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ import requests
4
+ from PIL import Image
5
+ import io
6
+
7
+ API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl-base-1.0"
8
+ api_key = os.getenv("API_KEY")
9
+
10
+ def query(payload):
11
+ headers = {"Authorization": f"Bearer {api_key}"}
12
+ response = requests.post(API_URL, headers=headers, json=payload)
13
+ return response.content
14
+
15
+ def image_generation(prompt):
16
+ input_prompt = {
17
+ "inputs": prompt,
18
+ }
19
+ image_bytes = query(input_prompt)
20
+ image = Image.open(io.BytesIO(image_bytes))
21
+ return image
22
+
23
+ title = "Stable Fiddusion XL"
24
+ description = "This app generates an image based on the provided prompt using the Stable Diffusion XL model."
25
+
26
+ gr.Interface(fn=image_generation, inputs="text", outputs="image", title=title, description=description).launch()