Kvikontent commited on
Commit
cefc456
Β·
verified Β·
1 Parent(s): 671431b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -15
app.py CHANGED
@@ -1,26 +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()
 
 
 
 
 
 
 
1
  import os
2
  import gradio as gr
3
+ from diffusers import DiffusionPipeline
4
  from PIL import Image
5
  import io
6
 
7
+ pipeline = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0")
8
  api_key = os.getenv("API_KEY")
9
 
10
+ def generate_image_with_stylization(prompt, style):
11
+ input_prompt = prompt
12
+ generated_image = pipeline.diffuse_text(input_prompt, stylize=True, style_prompt=style)
 
13
 
14
+ img = Image.fromarray(generated_image)
15
+ return img
 
 
 
 
 
16
 
17
  title = "Stable Fiddusion XL"
18
+ description = "This app generates an image based on the provided prompt using the Stable Diffusion XL model, applying stylization."
19
 
20
+ gr.Interface(
21
+ fn=generate_image_with_stylization,
22
+ inputs=["text", gr.inputs.Textbox(label="Style")],
23
+ outputs="image",
24
+ title=title,
25
+ description=description
26
+ ).launch()