bluenevus commited on
Commit
e4756d3
·
verified ·
1 Parent(s): 466f3f1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -14
app.py CHANGED
@@ -1,7 +1,7 @@
1
  import gradio as gr
2
  import google.generativeai as genai
3
  import requests
4
- import base64
5
 
6
  # List of popular styles
7
  STYLES = [
@@ -51,29 +51,27 @@ def generate_image(stability_api_key, enhanced_prompt, style, negative_prompt):
51
  url = "https://api.stability.ai/v2beta/stable-image/generate/sd3"
52
 
53
  headers = {
54
- "Accept": "application/json",
55
- "Content-Type": "application/json",
56
  "Authorization": f"Bearer {stability_api_key}"
57
  }
58
 
59
- payload = {
60
- "model": "sd3.5-large-turbo",
61
  "prompt": f"{enhanced_prompt}, Style: {style}",
62
  "negative_prompt": negative_prompt,
63
- "width": 1024,
64
- "height": 1024,
65
- "num_images": 1,
66
- "steps": 30,
67
- "cfg_scale": 7.5,
68
- "seed": 0,
 
69
  "output_format": "png"
70
  }
71
 
72
- response = requests.post(url, json=payload, headers=headers)
73
 
74
  if response.status_code == 200:
75
- image_data = response.json()['images'][0]['image_base64']
76
- return base64.b64decode(image_data)
77
  else:
78
  raise Exception(f"Image generation failed: {response.text}")
79
 
 
1
  import gradio as gr
2
  import google.generativeai as genai
3
  import requests
4
+ import io
5
 
6
  # List of popular styles
7
  STYLES = [
 
51
  url = "https://api.stability.ai/v2beta/stable-image/generate/sd3"
52
 
53
  headers = {
54
+ "Accept": "image/*",
 
55
  "Authorization": f"Bearer {stability_api_key}"
56
  }
57
 
58
+ data = {
 
59
  "prompt": f"{enhanced_prompt}, Style: {style}",
60
  "negative_prompt": negative_prompt,
61
+ "model": "sd3.5-large-turbo",
62
+ "width": "1024",
63
+ "height": "1024",
64
+ "num_images": "1",
65
+ "steps": "30",
66
+ "cfg_scale": "7.5",
67
+ "seed": "0",
68
  "output_format": "png"
69
  }
70
 
71
+ response = requests.post(url, headers=headers, data=data)
72
 
73
  if response.status_code == 200:
74
+ return response.content
 
75
  else:
76
  raise Exception(f"Image generation failed: {response.text}")
77